Sidebar Problem (3 posts)

  1. royng
    Posted 10 years ago #

    I am doing a design for my site and i do not get entries on my index page but on the sidebar i get the latest 2 entries with the first 25 words and a link to read on a entry but when i click on the entries page link, the page do not display the latest 2 post on the sidebar. I want it to show the post and on the sidebar show the other 2 posts how can can i get it done? below is the code to get the latest 2 post with the first 25 words

    <div id="update"><div class="updateheader"><strong>Updates</strong></div>
    <?php } ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php $temp_query = $wp_query; ?>
    <?php $my_query = new WP_Query('category_name=special_cat&showposts=2'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php endwhile; ?>
    <strong><?php the_title(); ?></strong><br>
    <small><?php the_time('F jS, Y') ?></small>
    <?php the_excerpt_reloaded(20); ?><br>
    <div class="updateheader"><strong><a>" rel="bookmark" title='Permanent Link to'>Read More</a><br></strong></div>
    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

  2. Kafkaesqui

    Posted 10 years ago #

    First, how does your sidebar work? Is it included on single post pages? Are there conditional tags (is_home() and such) defining when this "Updates" section is displayed?

    Second, you could *improve* the above code by removing the initial Loop (it's not used). However, I don't want to make recommendation on how to change it, as I'm unsure of a few things in your code:

    <?php } ?> What statement does this close?

    <?php $temp_query = $wp_query; ?> Where is this ever used?

  3. royng
    Posted 10 years ago #

    ok clean it up abit the <?php } ?> is to close my other function (K2 theme about function) and if i remove the <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> i will get an parse error and i using <?php get_sidebar(); ?> to get my sidebar and i am not using any conditional tags should i use those?

    I feel the problem is in my loop as when you view the post you are having 2 loops and the single post ends up in the sidebar and the second loop says Sorry, no posts matched your criteria.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.