Commit 51f48f21 by rajshah

toc done

parent 837811b9
...@@ -540,4 +540,23 @@ ...@@ -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); })(jQuery);
...@@ -94,31 +94,38 @@ get_header(); ...@@ -94,31 +94,38 @@ get_header();
Back to Blog Back to Blog
</a> </a>
</div> </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"> <div class="toc-title">
<h6>Table of Content</h6> <h6>Table of Content</h6>
</div> </div>
<div class="category-list"> <div class="category-list">
<ul class="wp-block-categories-list wp-block-categories"> <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> $xpath = new DOMXPath($dom);
</li> $headings = $xpath->query('//h2 | //h3');
<li class="cat-item cat-item-30"><a
href="http://192.168.1.89/makura-theme/category/digital-marketing/">Digital Marketing</a> foreach ($headings as $heading) {
</li> $id = sanitize_title($heading->nodeValue);
<li class="cat-item cat-item-33"><a href="http://192.168.1.89/makura-theme/category/updates/">News &amp; $heading->setAttribute('id', $id);
Updates</a> $table_of_contents .= '<li><a class="cat-item" href="#' . $id . '">' . $heading->nodeValue . '</a></li>';
</li> }
<li class="cat-item cat-item-1"><a
href="http://192.168.1.89/makura-theme/category/uncategorized/">Uncategorized</a> $table_of_contents .= '</ul>
</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>
</div>
</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> <p><?php echo the_field('read_time'); ?></p>
<div class="share-article2"> <div class="share-article2">
<h5>Share this article</h5> <h5>Share this article</h5>
......
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