Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter taghaboy

    (@taghaboy)

    in other way :
    i’d like to let the user to know about the pages (title of products) he was browsed.
    Thanks

    I think that you are going to have to do this yourself using sessions or cookies to keep track of what pages a user has visited.

    Thread Starter taghaboy

    (@taghaboy)

    that’s what i’m looking for, but i dont know how!!! is there any plugin who can do that?
    thanks

    Thread Starter taghaboy

    (@taghaboy)

    any help pls

    Here is some code that you can put in the /wp-content/themes/yourtheme/header.php at the top. No doubt someone could code this as a WordPress plugin, but I don’t know how to do this! Another alternative would be to use PHP sessions instead of cookies.

    <?php
    
    function updatePagesVisited()
    {
    	global $wp_query;
    
    	$post=$wp_query->get_queried_object();
    	$current_page_title=$post->post_title;
    	$days_to_store_cookie = 60;
    	$cookie_expiry_time = time() + $days_to_store_cookie*24*60*60;
    
    	if(isset($_COOKIE['pages_visited']))
    	{
    		$pages_visited=$_COOKIE['pages_visited'];
    		if(strlen($pages_visited)<1000)
    		{
    			if($current_page_title!=""&&$current_page_title!="index.php")
    			{
    				setcookie('pages_visited',$pages_visited.", ".$current_page_title,$cookie_expiry_time,"/");
    			}
    		}
    	}
    	else
    	{
    		setcookie('pages_visited',$current_page_title,$cookie_expiry_time,"/");
    	}
    }
    
    updatePagesVisited();
    ?>

    Then in your templates you would need:
    <?php echo $_COOKIE['pages_visited']; ?>

    wherever you want to display the pages visited. You can change the strlen<1000 if you want to keep the list to display on one line.

    Thread Starter taghaboy

    (@taghaboy)

    Thanks for the code,

    one question pls, how can i let it work with custom field?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘show the titles of the last visited posts?’ is closed to new replies.