Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Toggle on blog page for the_excerpt and the_content WordPress

  • SOLVED

Is there a way that I can have a link at the top of my blog page that allows a user to toggle how the blog page is displayed?

That way there will be 2 links at the top of the page, one for full text (the_content) and one for a summary (the_excerpt). Clicking either, would toggle all posts on the page to show either content or excerpt.

I know there's probably an ajax solution around somewhere but was hoping to not do it that way.

Answers (2)

2011-05-12

Kailey Lampert answers:

Something like this:


<?php if (isset($_GET['fulltext'])) { ?>
<a href="/blog/">View Excerpts</a>
<?php } else { ?>
<a href="/blog/?fulltext">View Full Text</a>
<?php } ?>


Then

<?php
if (isset($_GET['fulltext'])) {
the_content();
} else {
the_excerpt();
}
?>


Dan | gteh comments:

thanks I'll give that a shot shortly.


Dan | gteh comments:

What if I wanted to make this as an option in the admin panel instead? A setting the admin change to choose to display either or?


Kailey Lampert comments:

I've actually got a plugin that will add a full-text/summary option to the Settings > Reading page.

A small snippet will still have to placed in the theme in order to use the appropriate function based on the selection.

I've included a screenshot of the admin screen, let me know if that sounds like what you want, then I can give you the code.