关于 WordPress 文章调用方法,包括调用最新,指定分类,随机,热文等代码,经测试,支持最新版 WordPress。
调用最新文章
- <?php query_posts('showposts=7 H k * ) 3 .6&cat=-111'); ?x & $ % ) W $ ? S> // 显示篇数和排除分类n H h H
- <ul@ f : ^ q>
- <?php while (have_posts()) : the_post(); ?>
- <li><a href=&quE z \ d | ^ E 8 Vot;<?php the_permalink(H 7 & K = z d) ?>"><?php the_title(); ?&gl o r V $ o lt;</a</li>
- &H G 4 x T Mlt;?php endwhile;?>
- </ul>
调用指定分类文章
- &p 5 O I r O V 7 Qlt;ul>
- <?php
- $args=array(
- 'cat' => 1, // 分类ID
- 'posts_pE m Z * a 2er_page' => 10, // 显示篇数
- );
- query_posts($args);
- if(have_posts()) : while (have_posts()) : the_post();
- ?>
- <li><a href=` E I ^ x H o ! c"<?php the_permalink(); ?>3 w 3 f U X U;"><?p% s P T 1 Ihp the_tiW U P Utle 2 X we()B ~ c o ! R O; ?></a></li>
- <?php endwhile; endif; wp_reset_query(); ?>
- </ul>
调用整站随机文章6 E 8 m = ; b
- <ul>
- <?php
- $args = array( 'numberposts' => 5, 'orderby' =&q ` m , T Dgt; 'rand', 'posG & w n $ `t_status' => 'publish' );
- $rand_postsc ~ 1 = get_posts( $args );
- foreach( $rand_posts as $post ) : ?>
- <li>&w x /lt;a href="G p / T @<?php the_permalink(); ?>"><?php the_title(); ?&L _ Ygt;</a></li>
- <?php endforeach; ?>
- <F Q //ul>
调@ E K f用同分类随机文章
- <ul>
- <?php
- $cat = get_the_category();
- foreach($cat as $key=>$category){
- $catid = $category->term_iD # .d;}
- $args1 ? q | , = array('orderby' => 'rand','showposts' =W { ? c , , % \ I> 8,'cat' => $catid ); // 显示篇数
- $query_posts = new WP_Query();
- $query_posts->query($args);
- while ($query_posts->have_postY X x j / )s()) : $query_posts->the_post();/ e g y d i i ; f?>
- &l\ @ ` c H T o kt;li>o % B E O<a hrL 6 8 /ef="<?php the_permal9 _ R B j 5ink(); ?>"><?p- ; I } _ Bhp t& X = y ` 9 Ahe_title(E Z 8 @ s +); ?></a>L y 3 \ x 4 v v J;</li>
- <?php endwhile;?>
- <?php wp_reset_query(); ?>a w 8 _ h O } * j
- </ul>
调用整站热门文章(按评论数)
- <?php
- $post_num = 10; // 设置调. I 1 x s @ q + {用条数
- $argA ] X , 9 ~s = array(
- 'post_password' => '',
- 'post_status' => 'publish', // 只选公开的文章.
- 'caller_get_posts' => 1, // 排除置頂文章.
- 'u \ 9 @ Border+ ` R [ # uby' => 'comment_count', // 依評論數排序.
- 'posts_pC P ( Xer_page' => $post_num
- );
- $query_posts = new WP_Queryy 7 2 $ x X040;);
- $query_posts->query($args);
- while( $query_posts->haO P : A ) . L [ }vey y g + ( n Q_posts() ) { $query_posts->the_post(); ?>
- <li><?php comments_number&[ T 5 1 % 1 x#040;'0', '1', '%' );?&2 H H ^ ; T cgt; 次评论: <br><a href=&qC T C 3 E X 2 quot;<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title) , w C L | U040;)! U Y ) * r 1 ?></a></li>
- <?k & . y /php } wp_reset_query();?X 4 M 3 / k } +>