WordPress.org

Ready to get started?Download WordPress

Forums

Smarter Navigation
smarter-navigation cookies are not being created (3 posts)

  1. fogelfish
    Member
    Posted 1 year ago #

    I was trying to figure out why Smarter Navigation isn't working on one of my sites and then noticed that none of its cookies are showing up (I use Firebug to inspect cookies). I can see other cookies, such as the wordpress and wp-settings cookies.

    I have your plug-in working on another one of my sites. I can see the smarter-navigation cookies there. Can you tell why the problem site, using the same browser, would not save the smarter-navigation cookies?

  2. fogelfish
    Member
    Posted 1 year ago #

    Delving into your code a bit (and I'm new to WordPress) I see in your main.php the conditional statements inside the manage_cookie() function. You use the standard WordPress apply_filters() function to test the results of three functions named 'smarter_nav_clear', 'smarter_nav_read' and 'smarter_nav_set'. Those functions aren't defined anywhere (at least not in the code I have) so the values returned from apply_filters() default to the values in $clear_condition, $read_condition, or $set_condition. Since $clear_condition is always false, that leaves $read_condition always true in my pages and single posts, and finally that means the cookies are never set.

    Where are the 'smarter_nav_clear', 'smarter_nav_read' and 'smarter_nav_set' functions?

  3. fogelfish
    Member
    Posted 1 year ago #

    I resolved my issue. I am using the FlexForm theme. The crux was that I was linking to single posts from a Recent Posts section on a regular page. When a post loaded, the $read_condition resolved to TRUE (is_singular()) and the cookie never got set. To deal with that I split off reading and setting of the cookie from the same elseif structure and changed the condition for when to set it.

    $set_condition = !is_404() && (is_single() || is_archive());

    I also wanted to clear the cookie on regular pages, so I did this: $clear_condition = (is_singular() && !is_single());

    Since posts write the "p" query parameter to the cookie I also had to insert a test for a missing "cat" parameter and make things right. If the following is true

    if (!isset(self::$data['query']['cat'])) {

    then I retrieve the category of the currently loading post with

    wp_get_post_categories( $page->ID );

    and with that I replace the "p" parameter with the "cat" parameter (in the cookie and in $GLOBALS['wp_query']) and I also set $_COOKIE[self::NAME] equal to the revised $data;

    With the category now put in the expected variables, Smarter Navigation treats the current single post as if it had originated from an archive (because in an archive the "cat" parameter would have been set using the out-of-the box Smarter Navigation code).

    I think this will work only with posts that have a single category the way I've done things so far. I also want to refactor my work away from main.php so future updates to Smarter Navigation won't break them.

    Thanks for this plug-in. I never could have done any of this on my own.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags