如果想在wordpress主題制作過程中調(diào)用最新、熱門、隨機(jī)文章,可以使用wordpress自帶的widget側(cè)邊欄的小工具功能來實(shí)現(xiàn),但是這樣會(huì)影響到我們想自定義側(cè)邊欄的效果,當(dāng)然也有一些可以使用插件來實(shí)現(xiàn)這個(gè)功能的,不過使用插件始終對(duì)SEO方面有一定的影響,下面我給大家介紹一種不用插件也能實(shí)現(xiàn).
wordpress最新、熱門、隨機(jī)文章的調(diào)用方法.
1、最新文章的調(diào)用代碼:
- <ul>
- <?php $post_query = new WP_Query(‘showposts=10′);
- while ($post_query->have_posts()) : $post_query->the_post();
- $do_not_duplicate = $post->ID; ?>
- <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
- <?php endwhile;?>
- </ul>
2、熱門文章的調(diào)用代碼:
- <ul>
- <?php
- $post_num = 10; // 設(shè)置調(diào)用條數(shù)
- $args = array(
- ‘post_password’ => ”,
- ‘post_status’ => ‘publish’, // 只選公開的文章.
- ‘post__not_in’ => array($post->ID),//排除當(dāng)前文章
- ‘caller_get_posts’ => 1, // 排除置頂文章.
- ‘orderby’ => ‘comment_count’, // 依評(píng)論數(shù)排序.
- ‘posts_per_page’ => $post_num
- );
- $query_posts = new WP_Query();
- $query_posts->query($args);
- while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
- <li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title //開源軟件:Vevb.com
- (); ?></a></li>
- <?php } wp_reset_query();?>
- </ul>
3、隨機(jī)文章的調(diào)用代碼:
- <ul>
- <?php
- global $post;
- $postid = $post->ID;
- $args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’
- => 10);
- $query_posts = new WP_Query();
- $query_posts->query($args);
- ?>
- <?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>
- <li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php
- the_title_attribute(); ?>”><?php the_title(); ?></a></li>
- <?php endwhile; ?>
- </ul>
從上三種文章的代碼調(diào)用方法都測(cè)試過,其中最新文章和隨機(jī)文章的調(diào)用方法是沒有問題的,而熱門文章的調(diào)用代碼不知道為什么不能正常顯示,但是刪除了post_password’ => ”,這句代碼就可以正常調(diào)用,不知道有沒有那位大神可以留言告訴我原因,還有熱門文章的調(diào)用,如果想依瀏覽數(shù)來排序又是怎么實(shí)現(xiàn)的呢?期高手的出現(xiàn).
新聞熱點(diǎn)
疑難解答
圖片精選