Commit 51f48f21 by rajshah

toc done

parent 837811b9
......@@ -540,4 +540,23 @@
});
});
});
/* Table of Content */
function sanitizeTitle(text) {
return text
.toString()
.trim() // Remove leading and trailing whitespace
.toLowerCase() // Convert to lowercase
.replace(/[^a-z0-9\s-]/g, "") // Remove special characters
.replace(/\s+/g, "-") // Replace spaces with hyphens
.replace(/-+/g, "-"); // Remove multiple consecutive hyphens
}
$(function () {
$(".blog-detail-content h2, .blog-detail-content h3").each(function () {
var text = $(this).text();
var sanitizedText = sanitizeTitle(text);
$(this).attr("id", sanitizedText);
});
});
})(jQuery);
......@@ -50,9 +50,9 @@ get_header();
</defs>
</svg>
<?php
$post_content = get_the_content();
$reading_time = calculate_reading_time($post_content);
echo $reading_time; ?> mins read
$post_content = get_the_content();
$reading_time = calculate_reading_time($post_content);
echo $reading_time; ?> mins read
</div>
<div class="d-flex views">
<svg class="me-2" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
......@@ -94,31 +94,38 @@ get_header();
Back to Blog
</a>
</div>
<?php
$content = apply_filters('the_content', get_the_content());
if (!empty($content)) {
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
<div class="blog-category toc">
$table_of_contents = '<div class="blog-category toc">
<div class="toc-title">
<h6>Table of Content</h6>
</div>
<div class="category-list">
<ul class="wp-block-categories-list wp-block-categories">
<li class="cat-item cat-item-44"><a
href="http://192.168.1.89/makura-theme/category/company/">Company</a>
</li>
<li class="cat-item cat-item-30"><a
href="http://192.168.1.89/makura-theme/category/digital-marketing/">Digital Marketing</a>
</li>
<li class="cat-item cat-item-33"><a href="http://192.168.1.89/makura-theme/category/updates/">News &amp;
Updates</a>
</li>
<li class="cat-item cat-item-1"><a
href="http://192.168.1.89/makura-theme/category/uncategorized/">Uncategorized</a>
</li>
<li class="cat-item cat-item-31"><a
href="http://192.168.1.89/makura-theme/category/web-development/">Web Development</a>
</li>
</ul>
<ul class="wp-block-categories-list wp-block-categories">';
$xpath = new DOMXPath($dom);
$headings = $xpath->query('//h2 | //h3');
foreach ($headings as $heading) {
$id = sanitize_title($heading->nodeValue);
$heading->setAttribute('id', $id);
$table_of_contents .= '<li><a class="cat-item" href="#' . $id . '">' . $heading->nodeValue . '</a></li>';
}
$table_of_contents .= '</ul>
</div>
</div>
</div>';
echo $table_of_contents;
} else {
echo '<div class="table-of-content"><h4>No Content Available</h4></div>';
}
?>
<p><?php echo the_field('read_time'); ?></p>
<div class="share-article2">
<h5>Share this article</h5>
......@@ -154,15 +161,15 @@ get_header();
<div class="tags-wrapper">
<h5>Tags</h5>
<?php
$tags = get_tags();
if ($tags): ?>
<ul>
<?php foreach ($tags as $tag): ?>
<li><a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>"
title="<?php echo esc_attr($tag->name); ?>"><?php echo esc_html($tag->name); ?></a>
</li>
<?php endforeach; ?>
</ul>
$tags = get_tags();
if ($tags): ?>
<ul>
<?php foreach ($tags as $tag): ?>
<li><a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>"
title="<?php echo esc_attr($tag->name); ?>"><?php echo esc_html($tag->name); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
......@@ -182,65 +189,65 @@ get_header();
<div class="container">
<div class="row">
<?php $related_posts_section = get_field('related_post_section', 'option');
if (!empty($related_posts_section)):
?>
<h2><?php echo $related_posts_section['title']; ?></h2>
<div class="d-flex align-items after-title pb-60 justify-content-between">
<div class="col-lg-8 col-md-8 col-sm-8 paragraph">
<?php echo $related_posts_section['description']; ?>
</div>
<?php if ($link = $related_posts_section['link']):
$link_target = $link['target'] ? $link['target'] : '_self'; ?>
<div class="col-lg-3 col-md-3 col-sm-3 right-button d-flex align-items-center justify-content-end">
<a href="<?php echo $link['url']; ?>" target="<?php echo esc_attr($link_target); ?>"
class="btn btn-primary btn-start-project"><?php echo $link['title']; ?></a>
if (!empty($related_posts_section)):
?>
<h2><?php echo $related_posts_section['title']; ?></h2>
<div class="d-flex align-items after-title pb-60 justify-content-between">
<div class="col-lg-8 col-md-8 col-sm-8 paragraph">
<?php echo $related_posts_section['description']; ?>
</div>
<?php if ($link = $related_posts_section['link']):
$link_target = $link['target'] ? $link['target'] : '_self'; ?>
<div class="col-lg-3 col-md-3 col-sm-3 right-button d-flex align-items-center justify-content-end">
<a href="<?php echo $link['url']; ?>" target="<?php echo esc_attr($link_target); ?>"
class="btn btn-primary btn-start-project"><?php echo $link['title']; ?></a>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php
$related = get_posts(array('category__in' => wp_get_post_categories(get_the_ID()), 'numberposts' => 5, 'post__not_in' => array(get_the_ID())));
if ($related):
?>
$related = get_posts(array('category__in' => wp_get_post_categories(get_the_ID()), 'numberposts' => 5, 'post__not_in' => array(get_the_ID())));
if ($related):
?>
<div class="row">
<div class="row">
<div class="blog-carousel owl-carousel owl-theme owl-loaded owl-drag">
<?php foreach ($related as $post):
setup_postdata($post); ?>
<div class="item blog-card">
<a href="<?php the_permalink(); ?>">
<div class="blog-image-wrapper">
<?php the_post_thumbnail(); ?>
</div>
<div class="text-wrapper">
<!--<p><?php echo get_simple_tag_list(get_the_ID()); ?></p>-->
<h6><?php the_title(); ?></h6>
<?php the_excerpt(); ?>
<span><svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M16.25 3.625H3.75C3.40482 3.625 3.125 3.90482 3.125 4.25V16.75C3.125 17.0952 3.40482 17.375 3.75 17.375H16.25C16.5952 17.375 16.875 17.0952 16.875 16.75V4.25C16.875 3.90482 16.5952 3.625 16.25 3.625Z"
stroke="#005AFF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M13.75 2.375V4.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
<path d="M6.25 2.375V4.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
<path d="M3.125 7.375H16.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
</svg> <?php echo get_the_date('d, M Y', get_the_ID()); ?></span>
<div class="blog-carousel owl-carousel owl-theme owl-loaded owl-drag">
<?php foreach ($related as $post):
setup_postdata($post); ?>
<div class="item blog-card">
<a href="<?php the_permalink(); ?>">
<div class="blog-image-wrapper">
<?php the_post_thumbnail(); ?>
</div>
<div class="text-wrapper">
<!--<p><?php echo get_simple_tag_list(get_the_ID()); ?></p>-->
<h6><?php the_title(); ?></h6>
<?php the_excerpt(); ?>
<span><svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M16.25 3.625H3.75C3.40482 3.625 3.125 3.90482 3.125 4.25V16.75C3.125 17.0952 3.40482 17.375 3.75 17.375H16.25C16.5952 17.375 16.875 17.0952 16.875 16.75V4.25C16.875 3.90482 16.5952 3.625 16.25 3.625Z"
stroke="#005AFF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M13.75 2.375V4.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
<path d="M6.25 2.375V4.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
<path d="M3.125 7.375H16.875" stroke="#005AFF" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round"></path>
</svg> <?php echo get_the_date('d, M Y', get_the_ID()); ?></span>
</div>
</a>
</div>
</a>
<?php endforeach;
wp_reset_postdata(); ?>
</div>
<?php endforeach;
wp_reset_postdata(); ?>
</div>
</div>
<?php endif;
?>
?>
</div>
</section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment