WordPress.org

Ready to get started?Download WordPress

Forums

show the titles of the last visited posts? (7 posts)

  1. taghaboy
    Member
    Posted 5 years ago #

    how can i list the titles of the last visited posts?

  2. taghaboy
    Member
    Posted 4 years ago #

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

  3. s_ha_dum
    Member
    Posted 4 years ago #

    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.

  4. taghaboy
    Member
    Posted 4 years ago #

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

  5. taghaboy
    Member
    Posted 4 years ago #

    any help pls

  6. Pete555
    Member
    Posted 4 years ago #

    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.

  7. taghaboy
    Member
    Posted 4 years ago #

    Thanks for the code,

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

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic