1. öncelikle temanızı ve içeriğinizi yedekleyin.
2. temanızdaki </head> kodundan önce aşağdaki kodları yapıştırın. koddaki <style> kısmı biçimlendirme öğelerini içerir, şeklini şemalini beğenmezseniz burayı kurcalayın. Tablo hide all ve show all butonu içeriyor. İçerik dilinize göre kodda bu yazıları güncelleyin.
<style>
/* TOC genel stili */
#custom-table-of-contents {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
background-color: #f9f9f9;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
/* TOC başlık stili */
#custom-table-of-contents h2 {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
color: #333;
border-bottom: 2px solid #007BFF;
padding-bottom: 5px;
}
/* TOC liste stili */
#custom-table-of-contents ol {
list-style-type: none;
padding-left: 0;
margin: 0;
}
/* TOC liste öğesi stili */
#custom-table-of-contents li {
margin: 8px 0;
}
/* TOC bağlantı stili */
#custom-table-of-contents a {
text-decoration: none;
color: #007BFF;
font-size: 16px;
}
/* Bağlantı üzerine gelince */
#custom-table-of-contents a:hover {
text-decoration: underline;
color: #0056b3;
}
/* İç içe listeler için stili */
#custom-table-of-contents ol ol {
margin-left: 20px;
border-left: 2px solid #ddd;
padding-left: 10px;
}
/* Responsive tasarım için TOC uyumu */
@media (max-width: 768px) {
#custom-table-of-contents {
padding: 10px;
font-size: 14px;
}
#custom-table-of-contents h2 {
font-size: 16px;
}
#custom-table-of-contents a {
font-size: 14px;
}
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
var toc = document.getElementById("custom-table-of-contents");
if (toc) {
var contentArea = document.querySelector(".post-body");
if (contentArea) {
var headers = contentArea.querySelectorAll("h2, h3, h4, h5, h6");
if (headers.length > 0) {
var tocList = document.createElement("ul");
headers.forEach(function (header, index) {
if (!toc.contains(header)) {
var listItem = document.createElement("li");
var id = "toc-header-" + index;
header.id = id;
var link = document.createElement("a");
link.href = "#" + id;
link.textContent = header.textContent;
listItem.appendChild(link);
tocList.appendChild(listItem);
}
});
toc.appendChild(tocList);
// "Show all" ve "Hide all" düğmelerini oluştur
var toggleButtons = document.createElement("div");
toggleButtons.style.textAlign = "right";
toggleButtons.style.marginBottom = "10px";
var showAllButton = document.createElement("button");
showAllButton.textContent = "Show all";
showAllButton.style.marginRight = "5px";
showAllButton.onclick = function() {
tocList.style.display = "block";
};
var hideAllButton = document.createElement("button");
hideAllButton.textContent = "Hide all";
hideAllButton.onclick = function() {
tocList.style.display = "none";
};
toggleButtons.appendChild(showAllButton);
toggleButtons.appendChild(hideAllButton);
toc.insertBefore(toggleButtons, tocList);
}
}
}
});
</script>3. Aşağıdaki kodu da içerikte tablo eklemek istediğiniz yere yerleştirin. içerik diline göre ya da tablo başlığında ne yazmasını istiyorsanız "Table of Content" yazısını buna göre güncelleyin.
<div id="custom-table-of-contents"><h2>Table of Content</h2> </div>
4. kodu ihtiyacım olduğu için gpt'ye yazdırdım, burada da paylaşmak istedim. Mobil uyumludur. Makaledeki altbaşlıkları çeker. Yalnızca tablo eklenen sayfada çalışır site hızına genel etki etmez. Uygulamada gördüğüm anlık bir sıkıntı yok. Herkese işlerinde kolaylıklar dilerim.