Вопрос

/* ---------------------------------------------- */

/* Setting Post Limits on the HomePage */

/* ---------------------------------------------- */

if ( ! function_exists( 'the_post_limit' ) ) {

    if ( true == get_theme_mod( 'the_post_limit', true ) ) {

        function the_post_limit( $query ) {


            if ( is_admin() || ! $query->is_main_query() )

                return;



            if ( is_home() ) {

                // Display only 1 post for the original blog archive

                $query->set( 'posts_per_page', 8 );

                return;

            }

        }

        add_action( 'pre_get_posts', 'the_post_limit', 1 );

    }

}

The above code is sitting in the theme's functions.php. The purpose here is to restrict the number of posts on the home page.

The current number here is the number "8".

Can we somehow produce the number directly from the settings? I mean whatever number we put there. enter image description here

Это было полезно?

Решение

I modified your code just a bit. See if this works

 if ( ! function_exists( 'the_post_limit' ) ) {    
        if ( true == get_theme_mod( 'the_post_limit', true ) ) {    
            function the_post_limit( $query ) {   
                if ( is_admin() || ! $query->is_main_query() )    
                    return;    
                if ( is_home() ) {    
                    // Display only 1 post for the original blog archive
                       $get_default_posts_per_page = get_option( 'posts_per_page' );
                    $query->set( 'posts_per_page', $get_default_posts_per_page );    
                    return;    
                }    
            }    
            add_action( 'pre_get_posts', 'the_post_limit', 1 );

        }

    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top