• beanfair

    (@beanfair)


    I have created a page template to show up to 10 posts from a specific category and some static text below that the hot buy posts. The hot buy posts should be excerpts. Instead of excerpts of the actual posts showing, I am getting the excerpt of the static text appearing multiple times.
    Here is the link
    Here is the code for the excerpt loop. I don’t know why the permalink and post title are bringing up the correct posts but the excerpt is from the page, not the posts.

    <?php
    $args = array( 'posts_per_page=>5', 'orderby' => 'ASC', 'category' => 137 );
    $hotbuy_posts = get_posts( $args );
    foreach( $hotbuy_posts as $post ) : ?>
    	<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    	<?php the_excerpt(); ?>
    	</p>
    <?php endforeach; ?>

    Any assistance is greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    Thread Starter beanfair

    (@beanfair)

    I studied the get_posts link a lot yesterday. It states that the
    setup_postdata($post); is needed for ID and for content. It is also needed for excerpt. The excerpt now appears but now the static text of the page no longer appears.

    <?php
    $args = array( 'posts_per_page=>5', 'orderby' => 'ASC', 'category' => 137 );
    $hotbuy_posts = get_posts( $args );
    foreach( $hotbuy_posts as $post ) :  setup_postdata($post); ?>
    	<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    	<?php the_excerpt(); ?>
    	</p>
    <?php endforeach; ?>
    <div class="entry-content">
    <?php  the_content();
    wp_link_pages("\t\t\t\t\t<div class='page-link'>".__('Pages: ', 'thematic'), "</div>\n", 'number');
     edit_post_link(__('Edit', 'thematic'),'<span class="edit-link">','</span>') ?></div><!-- .entry-content -->

    The excerpts are for the hot buy posts while the content is for the static text on the page but the_content is not working.
    Any assistance is appreciated.

    Thread Starter beanfair

    (@beanfair)

    Correction to the above.
    It is displaying the content of the first hot buys post instead of the content of the page. I have no idea how to fix that. Any suggestions?

    esmi

    (@esmi)

    Why are you using the_excerpt()? Why is there a reference to the_content() outside the foreach loop?

    Thread Starter beanfair

    (@beanfair)

    As I stated in the original post, I need a page that shows the last excerpts of up to the last 10 posts in the category Hot Buy. Then the page needs to show content about hot buys in general. This text will rarely change.

    I was able to get the excerpts working for the post categories and show the page content by adding

    wp_reset_query();

    at the end of the excerpt loop. That allowed the_content() to pull from the page.

    Now if I can just get thumbnails to show in the excerpts, mission accomplished.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘second loop to show excerpts’ is closed to new replies.