• Hi,

    Although I’ve set to display 10 posts per page in wp-admin, but homepage still have only a single post, hides all previous ones.

    I’m designing a custom theme, here’s the loop code:

    <?php get_header(); ?>
    <?php if (have_posts()) : the_post(); ?>
    <!-- start content -->
    
    <div id="content">
      <div class="post" id="post-<?php the_ID(); ?>">
        <h1 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
          <?php the_title(); ?>
          </a></h1>
        <div class="entry">
          <?php the_content('Read the rest of this entry &raquo;'); ?>
        </div>
        <div class="clearfix">
          <!-- META -->
          <div class="meta">
            <!--<small>
            <?php the_time('F jS, Y') ?>
            |
            <?php the_author() ?>
            <?php edit_post_link('Edit', ' | ', ''); ?>
            </small>-->
            <!--<p class="tags">
          <?php the_tags('Tags: ', ', ', ' '); ?>
        	</p>-->
            <?php if (function_exists('sociable_html')) { print sociable_html(Array("del.icio.us", "StumbleUpon", "Facebook")); } ?>
            <div class="links">
              <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>
              <!--<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Permalink</a>-->
            </div>
          </div>
          <!-- /META -->
        </div>
      </div>
    </div>
    <!-- end content -->
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
    <?php endif; ?>
    <?php get_sidebar2(); ?>
    <?php get_sidebar(); ?>
    <!--
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    </div>
    -->
    <?php get_footer(); ?>

    What am I doing wrong?

    Any help appreciated. Many thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Vaughan

    (@vaughan-van-dyk)

    Hi,

    You need to include a while loop in your code, otherwise WordPress will just get the most recent post and finish.

    So change the following line of code from

    <?php if (have_posts()) : the_post(); ?>

    to

    <?php if (have_posts()) : while(have_posts()) : the_post(); ?>

    And change the following line of code from

    <?php else : ?>

    to

    <?php endwhile; else: ?>

    This code creates The Loop for a WordPress post page.

    Hope that helps.
    Vaughan

    Thread Starter 3zzy

    (@3zzy)

    Vaughan,

    That worked, many thanks. But a small problem now:

    Each post has its own container, eg:

    <div id="content">
      <div class="post post-1">
      post
      </div>
    </div>
    <div id="content">
      <div class="post post-2">
      post
      </div>
    </div>

    whereas it should be:

    <div id="content">
      <div class="post post-1">
      post
      </div>
      <div class="post post-2">
      post
      </div>
    </div>

    How would I fix this?

    Thanks

    you have to count the posts and then you <?php echo that count inside your div tag.

    https://www.tamba2.org.uk/wordpress/adsense/

    1/3 of the way down is an explanation of how you can do that..

    Thread Starter 3zzy

    (@3zzy)

    Nevermind, fixed it.

    Thanks anyway, Vaughan.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying only 1 posts on homepage’ is closed to new replies.