File: /var/www/stg-everycred.com/wp-content/themes/everycred/single.php
<?php
get_header();
$blog_text = get_field('blog_text');
$thumb_img = get_the_post_thumbnail_url($post->ID);
while (have_rows('blog_main_content')) : the_row();
$text_field = get_sub_field('content_blog');
$word_count = str_word_count($text_field);
$total_word_count += $word_count;
endwhile;
$min = $total_word_count/200;
?>
<!-- banner section -->
<section class="blog-detail-banner bg-black">
<div class="banner-content">
<div class="container h-100 p-relative">
<div class="left-banner h-100 d-flex flex-column justify-content-center">
<?php if ($blog_text) { ?>
<div class="font-16 text-bold"><?php echo $blog_text; ?></div>
<?php } ?>
<div class="font-42 text-medium blog-detail-title mt-2 mt-md-3 mt-xl-4">
<h1><?php the_title(); ?></h1>
</div>
<div class="d-flex mt-3 mt-md-4 mt-xl-5">
<div class="font-16 d-flex align-items-center">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/clock.svg" alt="clock"
class="me-2" />
<?php display_reading_time(); ?>
</div>
<div class="font-16 d-flex align-items-center ms-5 ps-5">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/calender.svg" alt="calender"
class="me-2" />
<?php echo get_the_date('jS F, Y', $post->ID); ?>
</div>
</div>
</div>
</div>
</div>
<?php if ($thumb_img) { ?>
<div class="banner-img overflow-hidden">
<img src="<?php echo $thumb_img; ?>" alt="blog-img" width="100%" height="100%" />
</div>
<?php } ?>
</section>
<!-- blog section -->
<section class="blog-content" id="scrollDiv">
<div class="container">
<div class="blog-content-inner d-flex align-items-start">
<div class="d-none d-lg-inline-block blog-sidebar py-4 mt-3">
<div class="font-18 text-bold text-black px-4">Table of Content</div>
<?php
// Get the content of the post
$content = get_the_content();
preg_match_all('/<(h2|h2 class="wp-block-heading")>(.*?)<\/(h2|h2)>/', $content, $matches);
if (!empty($matches[0])) { ?>
<ul class="mt-3 mb-0" id="toc">
<?php
/*
if(have_rows('blog_main_content')) :
while( have_rows('blog_main_content') ): the_row();
$content = get_sub_field('content_blog');
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
libxml_clear_errors();
$h2_tags = $dom->getElementsByTagName('h2');
foreach ($h2_tags as $h2) {
$anchor = sanitize_title(strip_tags($h2->textContent ));
echo '<li><a href="#' . $anchor . '" class="blog-list-link font-16">' . $h2->textContent . '</a>
</li>';
}
endwhile;
endif;
*/
?>
<?php
foreach ($matches[2] as $heading) {
$anchor = sanitize_title(strip_tags($heading));
$title = strip_tags($heading);
echo '<li><a href="#' . $anchor . '" class="blog-list-link font-16">' . $title . '</a></li>';
}
?>
<div class="d-flex mt-3">
<a target="_blank" href="https://twitter.com/intent/tweet?url=<?php the_permalink(); ?>"
class="social-link d-flex align-items-center justify-content-center me-2">
<img src="<?php echo site_url(); ?>/wp-content/themes/everycred/assets/images/twitter.svg"
alt="twitter" height="16">
</a>
<a target="_blank" href="https://www.instagram.com/?url=<?php the_permalink(); ?>"
class="social-link d-flex align-items-center justify-content-center me-2">
<img src="<?php echo site_url(); ?>/wp-content/themes/everycred/assets/images/instagram.svg"
alt="instagram">
</a>
<a target="_blank"
href="https://www.linkedin.com/sharing/share-offsite/?url=<?php the_permalink(); ?>"
class="social-link d-flex align-items-center justify-content-center me-2">
<img src="<?php echo site_url(); ?>/wp-content/themes/everycred/assets/images/linkedin.svg"
alt="linkedin" height="17">
</a>
</div>
</ul>
<?php } ?>
</div>
<?php
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="d-inline-block blog-content-detail" id="block-content">
<?php
if (get_the_content()) {
the_content();
}
/*
else {
if(have_rows('blog_main_content')) :
while( have_rows('blog_main_content') ): the_row();
$content = get_sub_field('content_blog');
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
libxml_clear_errors();
$h2_tags = $dom->getElementsByTagName('h2'); ?>
<div id="<?php
foreach ($h2_tags as $h2) {
echo sanitize_title(strip_tags($h2->textContent));
}
?>" class="blog-content">
<?php echo $content; ?>
</div>
<?php
endwhile;
endif;
} */
?>
</div>
<?php
endwhile;
endif;
?>
</div>
</div>
</section>
<?php
$blog_choose_heading = get_field('blog_choose_heading',28);
$blog_heading = get_field('blog_heading', 28);
$select_blog = get_field('select_blog', 28);
$blog_button_url = get_field('blog_button_url', 28);
if ($select_blog) {
?>
<section class="engineering-service bg-black">
<div data-aos="fade-up" data-aos-duration="800">
<div class="container">
<<?php echo $blog_choose_heading; ?> class="font-42 text-medium"><?php echo $blog_heading; ?></<?php echo $blog_choose_heading; ?>>
<div class="owl-carousel owl-theme case-study">
<?php foreach ($select_blog as $post) {
$feture_img = get_the_post_thumbnail_url($post->ID);
?>
<div class="item">
<a href="<?php the_permalink($post->ID); ?>"
class="engineering-card position-relative overflow-hidden d-block">
<div class="engineering-card-img">
<img src="<?php echo $feture_img; ?>" alt="case-study" />
</div>
<div class="engineering-detail">
<div class="font-20 text-black text-medium detail-text">
<?php echo get_the_title(); ?>
</div>
</div>
</a>
</div>
<?php }
wp_reset_postdata(); ?>
</div>
</div>
</div>
</section>
<?php } ?>
<section class="contact-section bg-white py-120">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
<div class="content">
<?php if (get_field('title_contact', 28)) { ?>
<div class="text-black font-42 text-medium"><?php echo get_field('title_contact', 28); ?></div>
<?php } if (get_field('description', 28)) { ?>
<div class="font-16 text-black text-medium mt-3">
<?php echo get_field('description', 28); ?>
</div>
</div>
<?php } if (get_field('button_url', 28)) { ?>
<a href="<?php echo get_field('button_url', 28); ?>"
class="mt-4 px-4 font-16 text-bold talk-btn black-btn d-flex align-items-center justify-content-center mx-0"><?php echo get_field('title_contact', 28); ?></a>
<?php } ?>
</div>
</div>
</section>
<?php get_footer(); ?>
<script>
// const menuItems = document.querySelectorAll('#toc li');
// function isInViewport(element) {
// const rect = element.getBoundingClientRect();
// return (
// rect.top >= 0 &&
// rect.left >= 0 &&
// rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
// rect.right <= (window.innerWidth || document.documentElement.clientWidth)
// );
// }smtp' );
// function setActiveMenuItem() {
// for (let i = 0; i < menuItems.length; i++) {
// const menuItem = menuItems[i];
// const sectionId = menuItem.querySelector('a').getAttribute('href').substring(1);
// const section = document.getElementById(sectionId);
// const link = menuItem.querySelector('a');
// const sectionTop = section.getBoundingClientRect().top - 120;
// if (sectionTop <= 0) {
// menuItems.forEach(item => {
// item.querySelector('a').classList.remove('active');
// });
// link.classList.add('active');
// } else {
// link.classList.remove('active');
// }
// }
// }
// window.addEventListener('scroll', setActiveMenuItem);
// jQuery(document).ready(function($) {
// Find all wp-block-heading elements
// $('.wp-block-heading').each(function() {~
// var titleText = $(this).text();
// var formattedText = titleText.replace(/[^\w\s]/gi, '').trim().replace(/\s+/g, '-');
// var id = formattedText.toLowerCase();
// $(this).attr('id', id);
// });
// });
</script>