上面是搬码源码网 abnma.com 经由过程收集网络收拾整顿的代码片断。搬码源码网小编此刻分享给各人,也给各人做个参考。
wordpress 怎样不应用插件完成挪用最新文章、热点文章和随机文章呢,对于 WP 文章挪用要领,包孕挪用最新,指定分类,随机,暖文等代码,经测试,撑持最新版 WordPress,这里我把代码记载上去,利便本身日后查望,也给各人参考之用。
挪用最新文章
<?php query_posts('showposts=6&cat=-111'); ?> // 显示篇数和解除分类 <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul>
挪用指定分类文章
<ul> <?php $args=array( 'cat' => 1,// 分类ID 'posts_per_page' => 10,// 显示篇数 ); query_posts($args); if(have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; endif; wp_reset_query(); ?> </ul>
挪用整站随机文章
<ul> <?php $args = array( 'numberposts' => 5,'orderby' => 'rand','post_status' => 'publish' ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
挪用同分类随机文章
<ul> <?php $cat = get_the_category(); foreach($cat as $key=>$category){ $catid = $category->term_id;} $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); // 显示篇数 $query_posts = new WP_Query(); $query_posts->query($args); while ($query_posts->have_posts()) : $query_posts->the_post();?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> <?php wp_reset_query(); ?> </ul>
挪用整站热点文章(按评论数)
<ul> <?php $post_num = 10; // 显示篇数 $args = array( ‘post_password’ => ”, ‘post_status’ => ‘publish’,// 只选公然的文章. ‘post__not_in’ => array($post->ID),//解除以后文章 ‘caller_get_posts’ => 1,// 解除置顶文章. ‘orderby’ => ‘comment_count’,// 依评论数排序. ‘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(); ?>"><?php the_title(); ?></a></li> <?php } wp_reset_query();?> </ul>
以上是搬码源码网(abnma.com)为你网络收拾整顿的全数代码内容,但愿文章可以或许帮你解决所碰到的步伐开提问题。假如感觉搬码源码网网站内容还不错,接待将搬码源码网网站保举给步伐员挚友。
总结
以上是搬码源码网为你网络收拾整顿的WordPress挪用最新,随机,热点,指定分类文章全数内容,但愿文章可以或许帮你解决WordPress挪用最新,随机,热点,指定分类文章所碰到的步伐开提问题。
假如感觉搬码源码网网站内容还不错,接待将搬码源码网网站保举给步伐员挚友。
请先
!