欢迎您光临92源码网,秉承服务宗旨,履行"站长"责任,销售只是起点,服务永无止境!

WordPress如何调用最新、热门文章和指定分类文章

作者 : admin 本文共1240个字,预计阅读时间需要4分钟
注:未经许可的【搬运】和【账号共享】可能会被取消VIP【每个都会记录ip,多ip封禁账号】
本站所有资源来源于网络,分享目的仅供大家学习和交流!不得使用于非法商业用途,不得违反国家法律。否则后果自负!

在我们WordPress主题制作过程过用到最多的应该是调用文章的代码了,而根据主题功能需求的多样性,调用文章的需求也变得花里胡哨。

下面路途吧分享了几段WordPress调用最新、热门文章的代码实例

最新文章

<?php query_posts(\\\\\\\'showposts=6&cat=1\\\\\\\'); ?> // 显示文章篇数和显示分类
<?php while (have_posts()) : the_post(); ?>

<a href=\\\\\\\"<?php the_permalink() ?>\\\\\\\" rel=\\\\\\\"external nofollow\\\\\\\" ><?php the_title(); ?></a>

<?php endwhile;?> 

指定分类文章

<?php query_posts(\\\\\\\'cat=1&showposts=5\\\\\\\'); //cat是要调用的分类ID,showposts是需要显示的文章数量 ?>
<?php while (have_posts()) : the_post(); ?>

<a href=\\\\\\\"<?php the_permalink(); ?>\\\\\\\" rel=\\\\\\\"external nofollow\\\\\\\"  rel=\\\\\\\"external nofollow\\\\\\\"  ><?php the_title(); ?></a>

<?php endwhile; wp_reset_query(); ?>

调用整站热门文章(按评论数排序)

<?php
$post_num = 10; // 显示篇数
$args = array(
\\\\\\\'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(); ?>

<a href=\\\\\\\"<?php the_permalink(); ?>\\\\\\\" rel=\\\\\\\"external nofollow\\\\\\\"  rel=\\\\\\\"external nofollow\\\\\\\"   ><?php the_title(); ?></a>

<?php } wp_reset_query();?>

 

本站声明:
1. 本站所有资源来源于网络,分享目的仅供大家学习和交流! 2. 不得使用于非法商业用途,不得违反国家法律。否则后果自负! 3. 本站提供的资源,都不包含技术服务请大家谅解! 4. 如有链接无法下载、失效或广告,请联系站长处理!

再次声明:如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


92源码网 » WordPress如何调用最新、热门文章和指定分类文章
Copyright © 2018-2022 92源码资源网 - All rights reserved 浙ICP备14006446号-2