Ready to get started?Download WordPress


Last Viewed Posts
[resolved] Show on view of second page after cookie is set. (2 posts)

  1. joshuaiz
    Posted 7 months ago #


    I'm using this to call the plugin in my template:

    <div id="recentlyviewed" class="clearfix">
    <?php if (function_exists('zg_recently_viewed')):  if (isset($_COOKIE["WP-LastViewedPosts"])) { ?>
        <h3>Recently Viewed:</h3>
    <?php zg_recently_viewed(); ?>
    <?php }  endif; ?>

    The problem is, once the cookie is set, it will show the conditional html above after the next page is viewed but there is nothing to show yet as the only last viewed post is the current page.

    Once a user goes to the next page (the second page after the cookie is set), then there is a post to show.

    I've tried to run a conditional check to see if there is a value in the second item in the cookie array but not having any luck.

    In plain english:

    Once the cookie is set, only show content if there is a value in the second item in the cookie.

    Does that make sense? How can I do this?



  2. joshuaiz
    Posted 7 months ago #

    I solved this...what I was missing was to unserialize the cookie data. What I ended up doing was wrapping that in another function so I could use mfunc/dynamic caching with WP Super Cache:

    function vizual_recently_viewed_posts() {
    	if (function_exists('zg_recently_viewed')):  if (isset($_COOKIE["WP-LastViewedPosts"])) {
    		$posts_array = unserialize($_COOKIE["WP-LastViewedPosts"]);
    			if (isset($posts_array[0])) { ?>
    				<h3>Recently Viewed:</h3>
    				<?php zg_recently_viewed(); ?>
    			<?php }


You must log in to post.

About this Plugin

About this Topic