WordPress.org

Support

Support » Plugins and Hacks » [Plugin: WP Single Post Navigation] Loop within category

[Plugin: WP Single Post Navigation] Loop within category

Viewing 3 replies - 1 through 3 (of 3 total)
  • @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 🙂

    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?

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WP Single Post Navigation] Loop within category’ is closed to new replies.