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

excerpts in twenty eleven WordPress

  • SOLVED

here's an extract from the content.php of twenty-eleven:



<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>

<?php if ( comments_open() && ! post_password_required() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>
</div>
<?php endif; ?>
</header><!-- .entry-header -->

<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>



I'm not an expert on php, but it looks to me like it says:
* if 'search' has been used, display the excerpt for the post
* else just show the post in the usual way ...

what I want is and extra bit of code that does this:
* if 'search' has been used, display the excerpt for the post (as before)
*(new) if there's text in the manual excerpt field, show that text and follow it with the the continue reading link
* else just show the post in the usual way ... (as before)

do-able?

cheers,
Andrewsan


Answers (3)

2013-04-09

Abdelhadi Touil answers:

Hi.
You can use this code:

<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>

<?php if ( comments_open() && ! post_password_required() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>
</div>
<?php endif; ?>
</header><!-- .entry-header -->

<?php if ( is_search() ) : // Display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php $my_excerpt = get_the_excerpt();
elseif ( $my_excerpt != '' ) : // Display Excerpts for manual excerpt ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>


I'v used this link as reference:
[[LINK href="http://codex.wordpress.org/Function_Reference/get_the_excerpt"]]http://codex.wordpress.org/Function_Reference/get_the_excerpt[[/LINK]]

Or you can use this one:

<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>

<?php if ( comments_open() && ! post_password_required() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>
</div>
<?php endif; ?>
</header><!-- .entry-header -->

<?php if ( is_search() ) : // Display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php elseif ( $post->post_excerpt ) : // Display Excerpts for manual excerpt ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>


I'v used this link as reference:
[[LINK href="http://wordpress.org/support/topic/show-only-excerpt-that-is-manually-filled-from-the-field-under-the-post"]]http://wordpress.org/support/topic/show-only-excerpt-that-is-manually-filled-from-the-field-under-the-post[[/LINK]]

Good luck :)


andrewsan comments:

thanks Abdelhadi ... I'll test v1 with my_excerpt first ...


andrewsan comments:

Abdelhadi's v2 works! :-)

problem solved / question closed

many thanks to all of you - Arna, Dbranes, Abdelhadi - for your interest and support

best regards
Andrewsan


Abdelhadi Touil comments:

Happy to hear that andrewsan :)
Good luck.

2013-04-09

Arnav Joy answers:

use this code , it will show continue reading in search page

<?php if ( 'post' == get_post_type() ) : ?>

<div class="entry-meta">

<?php twentyeleven_posted_on(); ?>

</div><!-- .entry-meta -->

<?php endif; ?>



<?php if ( comments_open() && ! post_password_required() ) : ?>

<div class="comments-link">

<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>

</div>

<?php endif; ?>

</header><!-- .entry-header -->



<?php if ( is_search() ) : // Only display Excerpts for Search ?>

<div class="entry-summary">

<?php the_excerpt(); ?>
<span style="float:right"><a href="<?php the_permalink();?>">continue reading</a></span>

</div><!-- .entry-summary -->

<?php else : ?>

<div class="entry-content">

<?php the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) ); ?>

<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>

</div><!-- .entry-content -->

<?php endif; ?>



andrewsan comments:

Um ... when I use 'search', I already get the excerpt and continue reading link:

what I want is for the Blog page to show the exerpt and continue reading link
when the editor has entered an excerpt manually ... is that what your code does?


Arnav Joy comments:

try this

<?php if ( 'post' == get_post_type() ) : ?>

<div class="entry-meta">

<?php twentyeleven_posted_on(); ?>

</div><!-- .entry-meta -->

<?php endif; ?>



<?php if ( comments_open() && ! post_password_required() ) : ?>

<div class="comments-link">

<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>

</div>

<?php endif; ?>

</header><!-- .entry-header -->



<?php if ( is_search() ) : // Only display Excerpts for Search ?>

<div class="entry-summary">

<?php the_excerpt(); ?>


</div><!-- .entry-summary -->

<?php else : ?>

<div class="entry-content">
<?php
if( has_excerpt() ):
the_excerpt();
else:
the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) );
endif;

wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>

</div><!-- .entry-content -->

<?php endif; ?>

2013-04-09

Dbranes answers:

You can try this to check if the excerpt field is set:

<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
<?php if ( comments_open() && ! post_password_required() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>
</div>
<?php endif; ?>
</header><!-- .entry-header -->
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php elseif(strlen(get_the_excerpt())>0) : ?>
<div class="entry-excerpt">
<?php the_excerpt(); ?>
</div><!-- .entry-excerpt -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&#x25b6;</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>


<strong>Edit:</strong> I added a Continue reading link to the excerpts.


andrewsan comments:

thanks dbranes, I'll test it ...


andrewsan comments:

hallo dbranes ... nearly there:

this triggers the 'exceprts and continue reading link' for *all* posts;

how to display the 'excerpt and continue reading link' only if there is text in the manual excerpts field of the post editor?


Dbranes comments:

updated the code, I tested it on my twentyeleven theme, and it works there.


Dbranes comments:

ps: TwentyEleven adds the Continue Reading link automatically to the function <strong>the_excerpt()</strong> via the <strong>the_excerpt</strong> filter:

function twentyeleven_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= twentyeleven_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );


so it is enough to use <strong>the_ecerpt()</strong> to get the link.


andrewsan comments:

very strange: on mine, it applies the excerpt to all posts, even if there's no manual entry
(see pic and www.andrewsan.com)

how to solve this?