WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Theme: Spun] Category display number of posts is off by one (2 posts)

  1. wolfteeth
    Member
    Posted 12 months ago #

    Hey all,

    Just switched my portfolio site over to WordPress, and decided on the Spun theme as my base for customization. Created a child theme to make some minor tweaks, but I've run into a wall.

    I have my Settings -> Reading -> "Blog pages show at most" value set to 10.

    On the home page, this displays correctly: 10 circles representing 10 posts.

    On any archive page (category or date), I instead see 9 circles representing 9 posts.

    I think this is a side-effect of the default setting for archives, where the archive name appears within a circle. But I altered the CSS to change that to an ordinary title.

    There must be some file in the theme tweaking the number of posts for archive pages, but I haven't been able to find it. Thanks in advance for any help! This is a pretty cool theme.

  2. wolfteeth
    Member
    Posted 12 months ago #

    Found the solution to this myself after poking around. Posting in case someone else was looking for the same answer.

    The function that was modifying the number of posts was in Spun's inc/extras.php:

    /**
     * Filter archives to display one less post per page to account for the .page-title circle
     */
    function spun_limit_posts_per_archive_page() {
    
    	if ( ! is_home() && is_archive() || is_search() ) {
    
    		$posts_per_page = intval( get_option( 'posts_per_page' ) ) - 1;
    		set_query_var( 'posts_per_page', $posts_per_page );
    	}
    }
    add_filter( 'pre_get_posts', 'spun_limit_posts_per_archive_page' );

    It's not set up to be overridable, so I wasn't sure I'd be able remove it in my child theme without hacking the parent theme. But it turns out I can call WordPress after setup is complete to remove the unwanted filter. I added this function to my child theme's functions.php file:

    /**
     * Hack to account for the child theme's removal of the .page-title circle
     */
    function spun_child_restore_posts_per_archive_page() {
    
    	remove_filter( 'pre_get_posts', 'spun_limit_posts_per_archive_page' );
    }
    add_filter( 'after_setup_theme', 'spun_child_restore_posts_per_archive_page' );

    I'm not sure if this is the "best practices" way to deal with this scenario, but it did get me the correct result without hacking the parent theme.

Reply

You must log in to post.

About this Topic