Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Conditionally Display Full Posts or Excerpts

By default, you can either display full-posts or excerpts when displaying your posts. This may be fine for common blogging purposes, but specialized blogs may find it beneficial to exercise control over which type of post format is displayed. Here’s how to conditionally display either full-post or excerpt based on the presence of a custom field named “full-post-display”.

To implement this technique, setup the following loop in your theme file(s):

<?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; ?>

Then, for any post that you would like to display with full-post formatting, simply add a custom-field of “full-post-display” and give it a value of “true”.