WordPress无插件实现相关文章目录调用 自定义样式

咱们不少网友会发现从WordPress官方平台下载的不少国外的主题没有页面相关文章调用列表,这个相对于SEO来讲可能会有部分影响,至少让用户看不到同类的文章。那就须要咱们本身添加这些功能,固然包括有一些插件能够实现,好比【Related Posts Thumbnails Plugin for WordPress 】插件是能够实现的,可是咱们不要这么复杂的插件,这里咱们就整理简单的代码实现。php

//无插件实现WordPress相关文章 Edit by cnwper.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>
相关文章
相关标签/搜索