繁体   English   中英

Wordpress while 循环:显示所有帖子而不是仅显示 10 个

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM