用chatGPT写一个wordpress文章目录函数
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;
}
版权声明:原创作品,未经允许不得转载,否则将追究法律责任。
本站资源有的自互联网收集整理,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
本文链接:子佩工作室https://zptheme.com/6137.html
许可协议:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
本站资源有的自互联网收集整理,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
本文链接:子佩工作室https://zptheme.com/6137.html
许可协议:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权