SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress: Controlling the_excerpt

    I have a sidebar that includes an excerpt of a specific page.

    When viewing the index.php, the excerpt appears in the sidebar properly. When viewing a single.php post, the sidebar displays the full content of the specific page, instead of an excerpt.

    I want it to always and only show an excerpt of a specific page in the sidebar. I need it to be unrelated to whether or not you're on index.php, single.php or anything like that. How can this be done?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Are you using a sidebar widget? I sounds like the code in your theme files is different for "index" and "single". eg.
    PHP Code:
    <?php the_excerpt(); ?>

  3. #3
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not using a widget. I'm using get_posts to obtain the excerpt of a specific page ID. This is my code:



    Code PHP:
    <?php global $post; $myposts = get_posts('numberposts=1&post_type=page&include=2'); ?><!-- DEFINE PAGE ID FOR ABOUT PAGE -->
     
    			<?php if( isset( $myposts ) && $myposts != '' ) :?>
    				<li><img src="<?php bloginfo('template_directory'); ?>/images/subhed_about.gif" alt="About"><br />
    					<?php foreach($myposts as $post) : setup_postdata($post);?>
    					<ul><?php the_excerpt(); ?><br />
    					<a href="<?php the_permalink(); ?>">Read More</a></ul>
    				<?php endforeach; ?>
    				</li>
    <?php endif;?>

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    That's from the correctly working index.php file? Is the single.php file using the_content() instead? Or maybe there's a conditional in it like
    PHP Code:
    <?php if ( is_category() || is_archive() ) {
        
    the_excerpt();
    } else {
        
    the_content();
    ?>
    Do you use the <!--more--> tag in your posts?

  5. #5
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    That's from the correctly working index.php file? Is the single.php file using the_content() instead? Or maybe there's a conditional in it like
    PHP Code:
    <?php if ( is_category() || is_archive() ) {
        
    the_excerpt();
    } else {
        
    the_content();
    ?>
    Do you use the <!--more--> tag in your posts?
    It's from the correctly working sidebar which is placed inside the index.php and single.php. However when you're viewing this sidebar.php within the single.php it shows the_content instead of the_excerpt.

    I want it to always show the_excerpt. Never the_content.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    If it's the same code in all the template files, I think you'll need to use the more tag (to create a "teaser" or edit the post in question manually by adding an excerpt for WP to use on non-index pages. The info here should clear things up http://codex.wordpress.org/Excerpt


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •