本文最后更新于 2023-03-01,已超过 365 天未更新,内容可能已失效。
function wp_article_index() {
global $post;
$content = $post->post_content;
$matches = array();
$output = '';
preg_match_all('/<h([1-6])[^>]*>(.*)<\/h[1-6]>/i', $content, $matches, PREG_SET_ORDER);
if (!empty($matches)) {
$output .= '<div id="wp-article-index">';
$output .= '<h2>目录</h2>';
$output .= '<ul>';
foreach($matches as $match) {
$output .= '<li><a href="#' . sanitize_title($match[2]) . '">' . $match[2] . '</a></li>';
}
$output .= '</ul>';
$output .= '</div>';
}
return $output;
}
除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。





登录后即可发表评论
全部评论 (0)