WordPress.org

Ready to get started?Download WordPress

Forums

Smarter Navigation
[resolved] W3 Total Cache and Date Archives (1 post)

  1. Parakoos
    Member
    Posted 2 years ago #

    I love Smarter Navigation, but I had two problems I wanted to fix.

    1. I wanted the plugin to play nice with W3 Total Cache. Out of the box, if a post got cached as 'coming from a tag' then any user receiving the cached version of the post would see the tag next/previous links, no matter if they were browsing by date or category.
    2. I wanted 'browsing by date' to work as normal. So if I am browsing by year=2011, then the last post of 2011 should show a next link to 2012.

    My solution is something of a long story. Please stay with me.

    Step 1: Stop W3 Total Cache cache posts 'tampered' by Smarter Navigation.

    If Smarter Navigation has changed a page from the default state, then we don't want to cache it. This step is simple. Under 'Performance -> Page Cache -> Rejected Cookies', add this line: smarter-navigation

    Step 2: Remove Smarter Navigation cookies from non-tampered with pages/posts/listings.

    Step 1 has a drawback. The smarter-navigation cookie is added everywhere on your site. But since this plugin is so awesomely extensible, we can fix that. Add the following to your functions.php:

    /* Smarter Navigation Filters */
    add_filter( 'smarter_nav_clear', 'tmn_smarter_nav_clear');
    
    function tmn_smarter_nav_clear( $condition ) {
       return !(				// Clear Unless
          is_single() 			// it is a single post
          || ( is_archive() && !is_date() )	// or any archive page except date
       );
    }

    Step 3: Use default link scripts on chronologically navigated posts.

    Step 2 has a drawback. For some reason, you get no link generated on posts when you are browsing by the default chronological order. No idea why. But the fix is to revert back to the default link generating script by WordPress.

    This has the benefit of your theme being resilient to the sudden removal of the Smarter Navigation plugin.

    So, in your single.php (or similar template), create your links in a similar piece of code:

    <?php if (! $_COOKIE['smarter-navigation']) { ?>
    	<!-- Navigate Chronologically -->
    	<div class="next"><?php next_post_link(); ?></div>
    	<div class="previous"><?php previous_post_link(); ?></div>
    <?php } else { ?>
    	<!-- Navigate by Tag/Category -->
    	<div class="next"><?php next_post_smart(); ?></div>
    	<div class="previous"><?php previous_post_smart(); ?></div>
    <?php } ?>

    Caveat

    I made this change in a hurry, so if there is a better way, please let me know!

    You can check out a working version of the hack at The Modern Nomad.

    http://wordpress.org/extend/plugins/smarter-navigation/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic