![](/img/trans.png)
[英]WordPress - 'The Loop' to show all posts, instead posts the title of the home page
[英]Wordpress while loop: Show all posts instead of just 10
我真的為這個而傷透了腦筋……這是 wordpress 中的一個小部件,在這種情況下顯示最后一個“帖子”“部分”。
我遇到的唯一問題是它只顯示最后 10 個項目......但我需要全部顯示。
有沒有人知道為什么會這樣?
我已經將所有值都設置為 3 到 10,但這並沒有解決我的問題,我真的不知道該怎么做了:(
問候, 羅伯特
public function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 50;
if ( ! $number )
$number = 50;
$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
/**
* Filters the arguments for the Recent Posts widget.
*
* @since 3.4.0
*
* @see WP_Query::get_posts()
*
* @param array $args An array of arguments used to retrieve the recent posts.
*/
$args = array( 'post_type' => 'section' );
$r = new WP_Query( $args );
/* $r = new WP_Query( apply_filters( 'widget_posts_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true
) ) ); */
?>
<?php echo $args['before_widget']; ?>
<div id="product_home_id" class="product_home">
<div class="page-homepage">
<ul>
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<li class="menu-item">
<?php /* <a class="anchor" href="<?php echo home_url(); ?>/#section-<?php the_ID(); ?>"><?php echo get_post_meta($post->ID, "url", true); ?><?php the_post_thumbnail(); ?><br/><?php the_title(); ?></a> */ ?>
<a class="anchor" href="<?php echo get_permalink(); ?>"><?php echo get_post_meta($post->ID, "url", true); ?><?php the_post_thumbnail(); ?><br/>
<div class="product_home_name_des">
<div class="product_description_home">
<?php the_field('product_description'); ?>
</div>
<span class="product_name">
<?php the_title(); ?>
</span>
</div>
</a>
<div class="product_content">
<a href="<?php echo get_permalink(); ?>">
<div class="arrow"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/arrow_image.png" /></div>
<p class="content"><?php the_field('product_subtitle'); ?></p>
</a>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php echo $args['after_widget']; ?>
<?php
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
}
只需將其添加到您的 $args 中:
'posts_per_page' => -1
您還可以將管理員中的默認設置更改為 10 以外的值。轉到 WordPress 管理員 > 設置 > 閱讀。 有一個“博客頁面最多顯示”的選項。
另一種方法可能是使用
'nopaging' => true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.