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?

3 Answers 3


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.

  • Would I just use a "theme switcher" plugin then - does that function work anymore?
    – Leanne
    May 14, 2011 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, 2011 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:

setcookie("mysite_cookie", "excerpt_view", time()+36000, "/");

then in your loop check if the cookie exists:

if (isset($_COOKIE["mysite_cookie"])){
// show excerpts
} else {
// show full posts

You can have the choice to display full content or excerpt by adding a custom field named "full-post-display" and then add following loop in your theme file:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $customdisplay = get_post_custom_values("full-post-display"); ?>

    <?php if (isset($customdisplay[0])) { ?>

        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <?php the_content(); ?>

    <?php } else { ?>

        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <?php the_excerpt(); ?>

    <?php } ?>
<?php endwhile; endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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