wordpress 调用相同tag文章

文章目录[隐藏]

出于网站优化以及用户体验需要 wordpress 侧边栏需要显示相同tag文章。

实现方法

侧边栏支持PHP

安装插件 Samsarin PHP Widget

相同Tag调用

<ul>
<?php
$post_num = 10;
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>

 

相关推荐

wordpress markdown插件

一直用wordpress收集整理文章,但是整体来说排版一直不是很好看,最近发现了一个wordpress mar ...