飞龙博客

feilong.org

如何调用与当前页面相同tag的文章列表

feilong.org 修订于2006-01-27 09:51:57 491 次浏览

飞龙不说闲话,测试如下代码吧。调用10条与当前页面相同tag的文章,这个列表常常用来做相关文章,可以避免使用插件。本日志更新网址:http://feilong.org/current-tag-posts-list 飞龙第4次修订于20100327

<ul>
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__in' => array($post->ID),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title();?> <?php comments_number(' ','(1)','(%)'); ?></a></li>
<?php
endwhile;
}
}
?>
</ul>

如果把这个列表再过滤一下,只列出当前分类下的当前tag的文章列表?只列出指定分类下的当前tag的文章列表?有高手请不吝赐教。

更新网址:https://feilong.org/current-tag-posts-list
最初发布:20060127 09:51:57 feilong.org 于广州

加入收藏夹,查看更方便。

所在分类: wordpress

新作:

AI音乐 blog money bui 教程 echarts 教程 eclipse 教程 html css 教程 IT趋势 js 教程 json 教程 mysql 教程 nodejs npm 教程 onblog SQLite 教程 tutorials vscode 教程 wap网站 winpe启动盘 wordpress 主机推荐 人工智能 前端开发 博客 名企名网 域名注册 常用软件 建站程序 操作系统 教程 数码 无线上网 日记 电子商务 电脑笔记本 网站 网站优化 网站开发 网站推广 网站策划 网络 虚拟现实 默认