• Resolved nipponese

    (@nipponese)


    For some reason, I can only get one post to show up on my front page. Under the Reading Setting, it is set to 10.

    This is the code from index.php in my theme:

    <?php get_header() ?>
    <?php get_sidebar() ?>
    <div id="content">
    
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<h2 class="post_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<div class="post"><?php the_content(); ?></div>
    		<div class="post_meta">
    			<p class="byline">Posted by <?php the_author_posts_link(); ?> on <?php the_date('Y.m.d', '<em>', '</em>'); ?> <!-- under <?php the_category(','); ?> --></p>
    			<!-- <p class="tags"><?php the_tags(); ?></p> -->
    			<?php if (function_exists('sharethis_button')) { sharethis_button(); } ?>
    		</div>
    
    		<?php endwhile; else: ?>
    		<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    		<?php endif; ?>
    
    </div>
    <?php get_footer() ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • are you positive that is the template that is being used to generate your home page? Does your theme have a home.php template file?

    to test, put a few words of output in the index.php file and refresh your homepage. If you see the text there, yes index.php is being used. If not, another template file is used.

    Quite likely you have a template file that is limiting the home page display to a single post using a query_posts or wp_query statement.

    Thread Starter nipponese

    (@nipponese)

    I am not sure why this is, but the answer to my problem was to move get_sidebar() to run after The Loop (previously I had it running before the query). Seems to fix everything.

    That depends on what code was running in the sidebar – it could have been hijacking the main query loop since it ran before the main page code.

    Thread Starter nipponese

    (@nipponese)

    This is what I have in sidebar.php
    That makes perfect sense. I am using a Loop to display the latest news item in the sidebar. Btw, if this the sort of situation I should be using rewind in?

    Here’s what I have in sidebar.php:

    <div id="sidebar">
    	<div id="updates">
    		<h2>News</h2>
    		<?php query_posts('category_name=news&showposts=1'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<a href="<?php the_permalink(); ?>"><?php the_date('Y.m.d'); the_excerpt(); ?>[Read more]</a>
    		<?php endwhile; else: ?>
    		<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    		<?php endif; ?>
    	</div>
    	<div id="twitter_div">
    			<h2>Twitter</h2>
    			<ul id="twitter_update_list"></ul>
    			<a href="http://twitter.com/Tokyo2Osaka" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a>
    	</div>
    	<div id="flickr">
    		<h2>Flickr</h2>
    		<?php echo do_shortcode('[flickr-gallery mode="recent"]'); ?>
    	</div>
    	<div id="download_proposal_wrapper">
    		<a id="download_proposal" href="http://tokyo2osaka2009.s3.amazonaws.com/Tokyo_to_Osaka_proposal.pdf"></a>
    	</div>
    	<a href="http://www.rickshawbags.com/"><img class="sponsorlogo" height="41" width="156" src="<?php bloginfo('template_directory') ?>/images/sponsor-rickshaw-trans.png" alt="Rickshaw" /></a>
    	<img class="sweetbike" height="143" width="232" src="<?php bloginfo('template_directory') ?>/images/bike-silo-trans.png" alt="Sweet Bike" />
    </div>

    instead of using query_posts and the default page loop use code like this in secondary loops
    (think I got this code’s syntax right)

    <div id="updates">
      <h2>News</h2>
    <?php $newsPosts = new WP_Query();
      $newsPosts->query('category_name=news&showposts=1');
      while ($newsPosts->have_posts()) : $newsPosts->the_post(); ?>
    	<a href="<?php the_permalink(); ?>"><?php the_date('Y.m.d'); the_excerpt(); ?>[Read more]</a>
      <?php endwhile; else: ?>
    </div>

    That, by the way, is why you were only getting one post before, because the query the main loop was executing was the same one that was in the sidebar, because of how you coded the sidebar query and with the sidebar code running before the main loop code. Even rewind posts would probably not have done it – would just have run the same query again.

    no, i already see an error
    last line should be
    <?php endwhile; ?>

    Thread Starter nipponese

    (@nipponese)

    Ahh, I am beginning to really understand the Loop better. Now I see the reason for such a long codex page on it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Only one post shows on front page, but Reading Setting is set to 10’ is closed to new replies.