Php WordPress从类别中获取标题
我想知道如何获取一些随机文章的标题/img/内容,但要从特定类别中获取 例如: 我有3个类别A、B和C,我的博客上有一个图像滑块。 我只想在滑块上显示属于A类的文章,而不是B和C类的文章。Php WordPress从类别中获取标题,php,wordpress,post,content-management-system,categories,Php,Wordpress,Post,Content Management System,Categories,我想知道如何获取一些随机文章的标题/img/内容,但要从特定类别中获取 例如: 我有3个类别A、B和C,我的博客上有一个图像滑块。 我只想在滑块上显示属于A类的文章,而不是B和C类的文章。 我怎样才能做到这一点呢?:) 下面的示例应该可以让您开始学习。它基本上使用一些条件调用get_posts()函数 返回5个职位 随机顺序 从特定类别 然后我们在返回的帖子上运行foreach来做我们想做的事情。您不必运行foreach,在下面的示例中,$rand_posts将保存一个数组post对象,您可
我怎样才能做到这一点呢?:) 下面的示例应该可以让您开始学习。它基本上使用一些条件调用get_posts()函数
- 返回5个职位
- 随机顺序
- 从特定类别
//在这里访问所有其他帖子信息,就像在一个正常的外观。(例如内容()、摘录()等)
下面的示例应该让您开始学习。它基本上是使用一些条件调用get_posts()函数
- 返回5个职位
- 随机顺序
- 从特定类别
//访问此处的所有其他帖子信息,就像正常的外观一样。(例如,_content(),_extract()等)
<?php
$cat_id = // Your category ID.
$args = array('numberposts' => 5, 'orderby' => 'rand', category => $cat_id);
$rand_posts = get_posts($args);
foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
// Access all other post information here just like in a normal look. (Ex. the_content(), the_excerpt(), etc, etc
<?php endforeach; ?>