WordPress.org

Ready to get started?Download WordPress

Forums

WP Single Post Navigation
Loop within category (4 posts)

  1. hoboscience
    Member
    Posted 2 years ago #

    I know this isn't the intention of the plugin but I would love to have only a forward option looping within a category. No reverse options. Is this possible?

    Thanks

    http://wordpress.org/extend/plugins/wp-single-post-navigation/

  2. daveshine (David Decker)
    Member
    Plugin Author

    Posted 2 years ago #

    @hoboscience:

    Hi there!
    Sorry for the little delay!

    Know what, your request is just possible :)

    You should add the following code to your theme/child theme's functions.php file (please make file backup before!):

    add_filter( 'wpspn_next_post_link', 'custom_wpspn_next_link' );
    /**
     * WP Single Post Navigation: Add custom filters for "next post link"
     */
    function custom_wpspn_next_link() {
    
        $args = array (
            'format'                => '%link',     // Change link format (default: %link)
            'link'                  => '«',   // Change link string (default: «)
            'in_same_cat'           => TRUE,       // Apply only to same category (default: FALSE)
            'excluded_categories'   => ''           // Exclude categories (default: empty)
        );
    
        next_post_link( $args['format'], $args['link'], $args['in_same_cat'], $args['excluded_categories'] );
    }
    
    add_filter( 'wpspn_previous_post_link', 'custom_wpspn_previous_link' );
    /**
     * WP Single Post Navigation: Add custom filters for "previous post link"
     */
    function custom_wpspn_previous_link() {
    
        return NULL;
    }

    It just adds only forward link and removes previous link! And it applies "only in category" to TRUE!
    If you want the arrow to appear on the other side you only have to change the « in my code to » - all ok? :)

    Hope that helps, Dave :)

  3. hoboscience
    Member
    Posted 2 years ago #

    Thanks for the response. That worked with one exception. I lose the forward arrow when I reach the final page in the category. Could this page loop back to the first page in the category?

  4. daveshine (David Decker)
    Member
    Plugin Author

    Posted 2 years ago #

    This is just intended default behavior provided by the core WordPress function that the plugin uses. The function has no paramaters for looping anything so it's just not possible. We can only hope together that they might implement something like that in future versions of WP...

    I hope that helps... :)
    -Dave.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic