Products
GG网络技术分享 2025-03-18 16:05 0
复制以下代码,然后将代码贴到当前主题的文章页模板中你需要调用相关文章的位置。
//WordPress相关文章<div class="related_posts">
<h3>相关文章</h3>
<ul>
<?php
$post_num = 8;
global $post;
$tmp_post = $post;
$tags = ''; $i = 0;
if ( get_the_tags( $post->ID ) ) {
foreach ( get_the_tags( $post->ID ) as $tag ) $tags .= $tag->name . ',';
$tags = strtr(rtrim($tags, ','), ' ', '-');
$myposts = get_posts('numberposts='.$post_num.'&tag='.$tags.'&exclude='.$post->ID);
foreach($myposts as $post) {
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
}
$post = $tmp_post; setup_postdata($post);
?>
</ul>
</div>
Demand feedback