• Resolved mikorka

    (@mikorka)


    Hi Ron,

    Is it possible to have “older” posts listed right below the slider? So that readers do not need to scroll over the same posts they already see in the slider. Let’s say we have the first 5 newest post displayed in the slider and then below the slider window it starts with the 6th.

    Thanks and regards!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Theme Author ronangelo

    (@ronangelo)

    The slider is only meant to show posts from the selected category and not necessarily the newest ones. Maybe using a different slider plugin would be easier to accomplish what you’re after.

    With the theme’s slider, what you can do is prevent posts from the slider from appearing on the main posts page so that there is no duplication.

    You can add something like this on your child-theme’s functions.php

    function my_query_exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() )
            $query->set( 'cat', '-20' );
    }
    add_action( 'pre_get_posts', 'my_query_exclude_category' );

    The 20 on the example above is the id/number of the category to be excluded. To get yours, go to the Categories page then hover over the selected category name. There will be a url on the status bar ( usually on the bottom part of your browser ) that contains the number.

    Thread Starter mikorka

    (@mikorka)

    Hi Ron,

    I tried above code but if I use that nothing is displayed on the front page below the slider. If I go to the archives, all the posts are visible there. I only use one category for my posts shown on the front page so it should be simple but something is missing from the code (?)

    Thanks for your help

    regards

    Thread Starter mikorka

    (@mikorka)

    Ah, I know what you meant…okay, so let’s say I would like to exclude the 5 newest posts from the front page and only displayed in the archive. What would be the code for that?

    Theme Author ronangelo

    (@ronangelo)

    Try this:

    function my_main_query_offset( $query ) {
        $offset = 5;
        $ppp = get_option('posts_per_page');
    
        if ( $query->is_paged ) {
            $page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
            $query->set('offset', $page_offset );
        }
        else {
            $query->set('offset',$offset);
        }
    }
    add_action( 'pre_get_posts', 'my_main_query_offset' );
    
    function my_main_query_adjust_pagination( $found_posts, $query ) {
    	return $found_posts - 5;
    }
    add_filter( 'found_posts', 'my_main_query_adjust_pagination', 10, 2 );

    Thread Starter mikorka

    (@mikorka)

    hmm…that removes the 5 newest posts from the slider too…something is still missing.

    Theme Author ronangelo

    (@ronangelo)

    function my_main_query_offset( $query ) {
    	if ( $query->is_home() && $query->is_main_query() ) {
    
    		$offset = 5;
    		$ppp = get_option('posts_per_page');
    
    		if ( $query->is_paged ) {
    			$page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
    			$query->set('offset',$page_offset);
    		}
    		else {
    			$query->set('offset',$offset);
    		}
    	}
    }
    add_action( 'pre_get_posts', 'my_main_query_offset' );
    
    function my_main_query_adjust_pagination( $found_posts, $query ) {
    	if ( $query->is_home() && $query->is_main_query() )
    		return $found_posts - 5;
    	else
    		return $found_posts;
    }
    add_filter( 'found_posts', 'my_main_query_adjust_pagination', 10, 2 );
    Thread Starter mikorka

    (@mikorka)

    That did the trick! Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Older posts right under slider?’ is closed to new replies.