释放双眼,带上耳机,听听看~!
今天给大家介绍一下在wordpress 文章末尾加上相关文章,因为之前的加了之后,个别朋友提出,有些主题调用标签会出错,所以修改了另一个版本的!亲测可用!
先看案例
具体案例可以 在文章里面看到
怎么实现的呢?下面是代码,复制代码到 文章函数 (single.php) 对应的位置里面 即可
因为各个主题不一样,这里以知更鸟4.4 为例
在主题编辑里面找到 文章底部对应的位置
<!-- 相关文章开始 --> <ul class="spostinfo"> <h3>80%的人都看过的文章</h3> <ul class="related_posts"> <?php $post_num = 8; $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%20the_permalink();%20?>" 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%20the_permalink();%20?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li> <?php $i++; } wp_reset_query(); } if ( $i == 0 ) echo '<li>没有相关文章!</li>'; ?> <br/><li><strong><?php _e( '版权声明:', 'begin' ); ?></strong>本文版权归<a href="http://www.loncons.com">龙萱坤诺</a>和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 <a href="http://www.loncons.com">龙萱坤诺</a> 整理发布,欢迎转载,转载请带版权。</li><br/> <li class="reprinted"><strong><?php _e( '来源: ', 'begin' ); ?></strong> 龙萱坤诺(https://www.loncons.com/),一个赏金社区!<p>本文链接:<a href="<?php%20echo%20Bing_current_url();?>" rel="bookmark" title="本文固定链接 <?php%20echo%20Bing_current_url();?>"><?php%20echo%20Bing_current_url();?></a></p></li> </ul> <!-- 相关文章结束 -->
相关专题

wordpress
WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的。用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。 wordpress 推荐模板/插件 虚位以待 马上入驻 虚位以待 马上入驻 虚位以待 马上入驻 推荐服务商 虚位…