WordPress.org

Support

Support » Themes and Templates » Excerpt tag

Excerpt tag

  • Hello, I am looking for a little help, I have designed and developing a website based around the TwentyEleven theme. (im not using the main parent theme, i am building on a copy)

    I am using a static home page and another page for blog posts, this was set in customize theme section in the admin gui.

    What I have is this, I have a <div> tag on the template which is based in the footer.php file. what I am struggling to acheive is pulling and excerpt from a blog post, this division is a news feed and required to post excerpts on blog posts only.

    I have used this bit of php code <?php the_excerpt(); ?> however this just seems to pull the page content rather than the blog excerpts.

    Any help with this would be fantastic.

    thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    you possibly need to create a loop with a custom query;

    start by reviewing:
    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/Class_Reference/WP_Query

    if you are stuck, please post the code of that <div> … or of hte full footer.php template (see http://codex.wordpress.org/Forum_Welcome#Posting_Code )

    Hello thank you, the query seems to resemble what I want however I’m new to php coding and just getting to grips with wp theming.

    Here is my footer, not much different from original other than the div tags in the site-generator area.

    Here’s my code

    <?php
    /**
     * The template for displaying the footer.
     *
     * Contains the closing of the id=main div and all content after
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    ?>
    
        </div><!-- #main -->
    	<footer id="colophon" role="contentinfo">
    
    			<?php
    				/* A sidebar in the footer? Yep. You can can customize
    				 * your footer with three columns of widgets.
    				 */
    				if ( ! is_404() )
    					get_sidebar( 'footer' );
    			?>
    
    			<div id="site-generator">
    
                <div id="Footer-Container-Left">
    			<div id="News-Footer"><?php the_excerpt(); ?>
    </div>
                </div>
    
                <div id="Footer-Container-right">
    			<div id="News-Footer-Right">Contact information</div>
                </div>
    
                    <div id="Shuffled">Designed by <a href="http://www.shuffled.co.uk" Title="Website Design by shuffled in Hull">shuffled.co.uk</a></div>
    
    			</div>
    	</footer><!-- #colophon -->
    
    </div><!-- #page -->
    
    <?php wp_footer(); ?>
    
    </body>
    </html>

    any further help would be great as I have been trying this all weekend lol

    Moderator Michael

    @alchymyth

    Forum Moderator

    change this section from:

    <div id="News-Footer"><?php the_excerpt(); ?>
    </div>

    to something like:

    <div id="News-Footer"><?php
    $news = new WP_Query( array(
      'posts_per_page' => 1, //number of posts
      'category_name' => 'news', //the category slug of the news posts
      'ignore_sticky_posts' => 1
    ));
    if( $news->have_posts() ) : while( $news->have_posts() ) : $news->the_post();
    the_excerpt();
    endwhile; endif; wp_reset_postdata(); ?>
    </div>

    the above eample assumes that the ‘news’ posts have the category ‘news’, and that you want to whow one latest post.

    for other possible parameters, see http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

    thank you, you are a legend. worked a treat and understand whats going on the php so can modify if need be.

    thank you

    just wondering can this be done with pages, for example the a particular page content shown on the home page in a div. similar to above just grabbing the content from a page rather than a blog post.?

    Moderator Michael

    @alchymyth

    Forum Moderator

    sure – you have the link to all the possible query parameters;

    also review:
    http://codex.wordpress.org/Function_Reference/get_pages
    or
    http://codex.wordpress.org/Function_Reference/get_page

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Excerpt tag’ is closed to new replies.