我有一家电子商务商店。我是php和wordpress的新手。(虽然我有python和ruby的背景,但我不懂php)
我有一个包含项目的页面。现在,最后20项显示在页面上(或类似的内容)。但我想显示的不是最后一个,而是这个类别中随机排列的项目。这是列出存档中的项目的代码。php文件:
<?php echo category_description( get_category_by_slug(\'category-slug\')->term_id ); ?></div>
<?php $col = 1; $counter = 0;?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php ++$counter;?>
.......
这段代码不是我写的。我单击了have posts()函数上的go to definition,并在wp includes/class wp中找到了它。查询php
* @return bool True if posts are available, false if end of loop.
*/
public function have_posts() {
if ( $this->current_post + 1 < $this->post_count ) {
return true;
} elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) {
/**
* Fires once the loop has ended.
*
* @since 2.0.0
*
* @param WP_Query $this The WP_Query instance (passed by reference).
*/
do_action_ref_array( \'loop_end\', array( &$this ) );
// Do some cleaning up after the loop
$this->rewind_posts();
} elseif ( 0 === $this->post_count ) {
/**
* Fires if no results are found in a post query.
*
* @since 4.9.0
*
* @param WP_Query $this The WP_Query instance.
*/
do_action( \'loop_no_results\', $this );
}
$this->in_the_loop = false;
return false;
}
此外,当我单击go to definition时,它建议我在文件中选择第二个选项:query。php
* @since 1.5.0
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @return bool
*/
function have_posts() {
global $wp_query;
return $wp_query->have_posts();
}
我该怎么办?