[英]Get post from a single category with have_posts () WordPress
我正在展示我使用wordpress开发的外部网站上博客的最新文章。
<?php
//Include WordPress
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
//Define quantos posts serão exibidos
query_posts('showposts=3');
?>
<?php while (have_posts()): the_post(); ?>
<li>
<h4><?php the_title(); ?></h4>
<span><?php the_time("d/m/Y"); ?></span>
<?php the_category_ID(); ?>
<?php the_content(); ?>
<div>
<a href="<?php the_permalink(); ?>">« Leia Mais...</a>
</div>
</li>
<?php endwhile;?>
关键是该博客分为两类,我只想显示其中一类。
链接我得到这些功能的地方。
查询帖子时,还可以添加类别条件,如下所示:
query_posts('showposts=3&cat=CAT_ID'); //replace CAT_ID with the category ID that you want
由于您提到要显示最新帖子,因此您可能需要执行以下操作:
query_posts('showposts=3&cat=CAT_ID&orderby=date&order=DESC');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.