Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
makura-2025
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Raj Shah
makura-2025
Commits
51f48f21
Commit
51f48f21
authored
Jan 02, 2025
by
rajshah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toc done
parent
837811b9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
19 deletions
+45
-19
style.js
assets/js/style.js
+19
-0
single-post.php
single-post.php
+26
-19
No files found.
assets/js/style.js
View file @
51f48f21
...
...
@@ -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
);
single-post.php
View file @
51f48f21
...
...
@@ -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
&
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>
</div>
<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>'
;
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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment