Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am wondering if there is a way to give users the option of choosing between two formats of displaying posts (index/archive/search result template options) - either view full post, or excerpts?

So on the home page you could have a setting "view full posts" and save that setting so that each time the viewer visits, they're served the full post index template instead of the excerpted one (and vice versa) - how can this be achieved?

share|improve this question

2 Answers 2

Milo beat me to the punch while I was writing this but I will expand on his answer.

To set your cookie an easy method would be to use jQuery Cookie.

Download the plugin and include the cookie js via wp_enqueue_script with jquery as a dependency.

For your buttons:

<input id="excerpt_view" type="button" value="Show Excerpts" />
<input id="full" type="button" value="Show Entire Posts" />

Your js to save the cookie.

jQuery(function($) {

    $('#excerpt_view').click(function(e) {
         $.cookie('mysite_cookie', 'true', { expires: 30 });
    });
    $('#full').click(function(e) {
         $.cookie('mysite_cookie', null);
    });

});

The PHP conditional in Milo's answer will read the cookie. The excerpt_view button will set the cookie and cause the conditional to return true and show the excerpt. The full view button deletes the cookie which will cause the conditional to return false and show the full posts.

share|improve this answer
    
Would I just use a "theme switcher" plugin then - does that function work anymore? –  Leanne May 14 '11 at 12:27
    
I guess I'm confused about how to write a query within the index page to say "if they've clicked excerpt_view, show this...." else "if they've clicked full_post, show this". –  Leanne May 14 '11 at 12:34

you could set a cookie and then check it in the loop. I've done this in the past with a check box hooked to an ajax call to a little php script:

<?php
setcookie("mysite_cookie", "excerpt_view", time()+36000, "/");
?>

then in your loop check if the cookie exists:

<?php
if (isset($_COOKIE["mysite_cookie"])){
// show excerpts
} else {
// show full posts
}
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.