无需插件快速实现WordPress相关文章调取

1年前 (2022-11-15)阅读147回复0
翱翔MJ
翱翔MJ
  • 管理员
  • 注册排名1
  • 经验值3344
  • 级别管理员
  • 主题538
  • 回复327
楼主
//无插件实现WordPress相关文章 Edit by laobuluo.com<div class="related_posts"><h3>这几篇文章你可能也喜欢:</h3><ul><?php
$post_num = 10;$exclude_id = $post->ID;$posttags = get_the_tags(); $i = 0;if ( $posttags ) {$tags = ''; foreach ( $posttags as $tag ) $tags .= $tag->term_id . ',';$args = array('post_status' => 'publish','tag__in' => explode(',', $tags),'post__not_in' => explode(',', $exclude_id),'caller_get_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num,);query_posts($args);while( have_posts() ) { the_post(); ?><li><a rel="bookmark" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li><?php
$exclude_id .= ',' . $post->ID; $i ++;} wp_reset_query();}if ( $i < $post_num ) {$cats = ''; foreach ( get_the_category() as $cat ) $cats .= $cat->cat_ID . ',';$args = array('category__in' => explode(',', $cats),'post__not_in' => explode(',', $exclude_id),'caller_get_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num - $i);query_posts($args);while( have_posts() ) { the_post(); ?><li><a rel="bookmark" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li><?php $i++;} wp_reset_query();}if ( $i == 0 ) echo '<li>没有相关文章!</li>';?></ul>
</div>


1
回帖

无需插件快速实现WordPress相关文章调取 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息