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>
相關文章
相關標籤/搜索