zeitgrund blog

Plugin Last Viewed Posts (english)

Samstag, 8. Dezember 2007 um 14:59 Uhr in Last Viewed Posts, Plugins

Download the latest release (0.7.1) of the plugin Last Viewed Posts

For German description click here / für deutsche Beschreibung hier klicken

Description:
This plugin displays the posts (or pages) that have been recently viewed by the visitor (single view).
The posts are saved in in a cookie and by default the last 10 posts that have been visited are displayed.
Note that this is NOT a global listing of recently viewed posts by all users! Nothing is stored in the database.
Every vistor has his own unique listing of the single posts he has viewed.

If cookies are not accepted or no single post has been clicked, no output will be displayed.
The plugin comes with a widget and a template tag.

Screenshot

Download:
last_viewed_posts.zip (3kb)

Compatiblity:
This Plugin needs at least WordPress 2.1 but is compatible up to WordPress 2.7.

Changelog:
0.6: First public release.
0.7: Pages can now be recognized (optional). Custom Loop is not longer used. Now we make a database query to get the post title.
0.7.1: Post/Page ID values in cookie are sanitized for output.

Use:
Viewed posts are always tracked as long as the plugin is active and the visitor has enabled the cookies.

Download and unzip the plugin file. Upload last_viewed_posts.php to your /wp-content/plugins/ directory.
Go to the admin backend and activate the plugin.

To display the list, you can use the widget that comes with the plugin or use the following code and place it anywhere you want to, but outside the loop, e.g. sidebar.php :

<?php if (function_exists('zg_recently_viewed')): if (isset($_COOKIE["WP-LastViewedPosts"])) { ?>
<h2>Last viewed posts</h2>
<?php zg_recently_viewed(); ?>
<?php } endif; ?>

The single template tag is shown below, but I recommend to use the code shown above.
It prevents you from displaying a blank list if the visitor has cookies disabled or did not view any single post yet.
<?php zg_recently_viewed(); ?>

By default the cookie expires after 360 days and the number of entries that are displayed is 10.
To change these values, edit the last_viewed_posts.php between the equals sign and the semicolon:
$zg_cookie_expire = 360; // After how many days should the cookie expire? Default is 360.
$zg_number_of_posts = 10; // How many posts should be displayed in the list? Default is 10.
$zg_recognize_pages = true; // Should pages to be recognized and listed? Default is true.

This Plugin is released under the GPL.



21 Kommentare zu ' Plugin Last Viewed Posts (english) '

Kommentar schreiben

  1. cal schrieb:

    Looks really cool, thanks for sharing!

    20. Dezember 2007 um 1:01

  2. harald schrieb:

    Momentan erscheinen in der Liste keine doppelte Einträge. Ist es möglich Titel in chronologischer Reihenfolge so oft anzuzeigen wie eben der Artikel aufgerufen worden ist?
    Bsp: title1 title1 title2 title1 titleX.

    23. Dezember 2007 um 15:32

  3. Olaf schrieb:

    Will man doppelte Einträge anzeigen lassen, so braucht man nur eine Änderung vornehmen. In der PHP-Datei des Plugins muss man nur folgende Zeilen entfernen:

    if (in_array($zg_post_ID, $zg_cookiearray)) { // If the item is already
    included in the array then remove it
    $zg_key = array_search($zg_post_ID, $zg_cookiearray);
    array_splice($zg_cookiearray, $zg_key, 1);
    }

    In Version 0.7 entspricht es den Zeilen 69-72.

    24. Dezember 2007 um 11:03

  4. Wordpress themes and plugins for the week schrieb:

    [...] Last viewed posts – This is a new idea. This plugin will show the latest viewed posts by other visitors. You’ve heard about recent posts, recently commented posts etc, now try this one. [...]

    26. Dezember 2007 um 7:18

  5. miklas schrieb:

    Very nice plugin. I have a question though. I installed the polyglot plugin and noticed that the lastviewed post plugin displays the [lang_en][lang_da] tags of the title. Any workaround?

    Great work.

    Regards, Miklas.

    14. Juli 2008 um 9:03

  6. Olaf schrieb:

    @miklas:
    That’s because the titles are directly read from the database.
    So I recommend the older version 0.6 which makes no datbase queries and uses the wordpress loop instead.
    http://blog.zeitgrund.de/last_viewed_posts0_6.zip

    19. Juli 2008 um 0:23

  7. jrgd schrieb:

    it works like a charm! thanks!
    i would love to have it display images or extract of the content – i will try and maybe come back with a modified version if that works

    6. Oktober 2008 um 18:29

  8. Olaf schrieb:

    @jrgd:
    It’s may easier if you use an older version of the plugin: http://blog.zeitgrund.de/last_viewed_posts0_6.zip
    In function zg_recently_viewed() you could use code like the_excerpt then.

    6. Oktober 2008 um 18:55

  9. jrgd schrieb:

    olaf: thanks! will try that – at the moment i’m fighting with: how to know a thumbnail is actually a thumbnail :)

    6. Oktober 2008 um 19:01

  10. WordPress Plugin Releases for 11/18 | Wordpress Blog NL schrieb:

    [...] Last Viewed Posts [...]

    19. November 2008 um 19:17

  11. WeblogToolsCollection Español » Blog Archive » Novedades Plugins de WordPress 18/11 schrieb:

    [...] Last Viewed Posts [...]

    21. November 2008 um 3:11

  12. WordPress Plugin Releases for 11/18 » All About Technologies schrieb:

    [...] Last Viewed Posts [...]

    23. November 2008 um 15:45

  13. Adrian schrieb:

    Great plugin, up until now.

    Whenever it is enabled and I login, this is the following message:

    Warning: Cannot modify header information – headers already sent by (output started at /home/launchpa/public_html/clean/s/wp-content/themes/adrian_7/blank_page.php:7) in /home/launchpa/public_html/clean/s/wp-content/plugins/last_viewed_posts.php on line 87

    12. Januar 2009 um 16:42

  14. Olaf schrieb:

    @Adrian: Seems to be a problem with your theme. Could you show me the code of your blank_page.php? It’s may better to send it to me via E-Mail (you can see my address in the footer of my blog).

    12. Januar 2009 um 18:15

  15. Wordpress themes and plugins for the week 6 | aw-aw.com schrieb:

    [...] Last viewed posts – This is a new idea. This plugin will show the latest viewed posts by other visitors. You’ve heard about recent posts, recently commented posts etc, now try this one. [...]

    21. Januar 2009 um 18:02

  16. Ray schrieb:

    Hi Olaf,

    I was just wondering if it is possible to use a loop with your plugin.

    The reason is I would like to use the “Get The Image” plugin, as well as the ability to output a few custom fields.

    Is this possible?

    10. Juli 2009 um 8:34

  17. Olaf schrieb:

    @Ray:
    Yes this is possible with an older version of the plugin: http://blog.zeitgrund.de/last_viewed_posts0_6.zip

    10. Juli 2009 um 9:27

  18. Craig schrieb:

    Hello,

    This plugin sounds just what I am looking for. I have tried both versions but they dont seem to show up in my sidebar. I have tried adding the template code above, and also via the widget.

    I have tried similar plugins, but for different content and these seem to work OK. I am unsure if it is a problem with my template or I have done something wrong.

    It is as though the function doesnt exist!

    Many thanks.
    Craig

    21. Januar 2010 um 5:55

  19. Olaf schrieb:

    @Craig:
    I guess it’s a problem with cookies. You should check, if they’re blocked or something else.

    And important is, that the widget is only shown, when you have visited pages/posts yet.

    21. Januar 2010 um 18:51

  20. Kamal schrieb:

    Hi,
    Thanks for this unique plug-in, i use it with my theme and it work so good,
    i’d like to knwo how can add this code:

    <a href="">
    <img src=""/>

    <img src="/img/no-img.jpg"/>


    to work with yours:


    Last viewed posts

    10. Februar 2010 um 17:47

  21. Kamal schrieb:

    ok the code dont work, so i replace the tags with the (-)

    -?php if ( $var_img01 ) { ?-
    -a href="-?php the_permalink() ?-"-
    -img src="-?php echo $var_img01; ?-"/-
    -/a-
    -?php } else { ?-
    -img src="-?php bloginfo('stylesheet_directory'); ?-/img/no-img.jpg"/-
    -?php } ?-
    -/code-
    to work with yours:
    -code-
    -code--?php if (function_exists('zg_recently_viewed')): if (isset($_COOKIE["WP-LastViewedPosts"])) { ?-
    -h2-Last viewed posts-/h2-
    -?php zg_recently_viewed(); ?-
    -?php } endif; ?-

    10. Februar 2010 um 17:51

Kommentar verfassen

Zeilen und Absätze brechen automatisch um, E-Mail Adresse wird nicht veröffentlicht (ist aber obligatorisch), HTML erlaubt: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>