Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have restricted to display 20 posts on index.php, but also I want to add a link to display all posts without restrictions. Any advices on how to achieve this? Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could create a template called all-posts.php and place this code inside of it:

<?php /* Template Name: All posts */ ?>
<?php get_header(); ?>
<div id="primary">
  <div id="content" role="main">
    <div class="entry">
        <?php
          $args = array( 'numberposts' => -1 );
          $lastposts = get_posts( $args );
          foreach($lastposts as $post) : setup_postdata($post); ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <?php the_content(); ?>
      <?php endforeach; ?>
    </div><!-- .entry -->
  </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Now you would save that file, upload it to your theme's main directory. Next you could create a page called All Posts, or whatever you wanted. When you are in the New Page or Page Edit screen, just choose the new template you just made called All Posts from the Page Attributes drop-down list in the right side of the edit pages screen.

Click update and add the page to your menu. You will now have a page that shows all posts. You can copy the URL and use it to link to all posts from the page you are speaking of.

REVISED TO SHOW HOW TO ADD "NEW DIV"

There really isn't a need to add an extra div tag for this template. Each post will have it's own id by default. If you use Firefox you can install one or both of the following plug-ins to inspect each post for it's unique ID:

Web Developer Plug-in

FireBug Plug-in

Once you have them installed get familiar with the available tools and you'll have access to lots of valuable data. I'm going to past the code again with a new div added just in-case you don't figure out how to identify the posts as I've explained.

Code with new DIV Tag:

<?php /* Template Name: All posts */ ?>
<?php get_header(); ?>
<div id="primary">
  <div id="content" role="main">
    <div class="entry">
        <?php
          $args = array( 'numberposts' => -1 );
          $lastposts = get_posts( $args );
          foreach($lastposts as $post) : setup_postdata($post); ?>
     <div class="new-div">
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <?php the_content(); ?>
    </div>
      <?php endforeach; ?>
    </div><!-- .entry -->
  </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

The new DIV is the one called "new-div". You can add a little css to the new div so you can see it in action. Just add this to your style.css file for a red border (just for testing purposes):

.new-div {
width:100%;
height:100%;
display:block;
border:1px solid red;
}
share|improve this answer
    
Thanks, that is almost what I want. The only problem is that I want to wrap these posts with divs (one post-one div wrap), but if I add a div now it adds up only like an element to the site but not to the posts. What I want to say, that I want - when I add one div it should wrap each post not only apply to the site. I hope you got it what I want. You can inspect what I have at the moment in - bellated.us.lt/?page_id=81 –  Domante Stirbyte Aug 29 '11 at 15:39
    
View the code above to see how to wrap them with a div tag. –  Jeremy Jared Aug 29 '11 at 18:38
    
Thanks. Worked! –  Domante Stirbyte Aug 29 '11 at 21:22
    
One last question. I would like to wrap up this div with a title permalink. Now I have: <div class="new-div" a href="<?php the_permalink(); ?>"><?php the_title(); ?> </div> </a> but its not working –  Domante Stirbyte Aug 29 '11 at 23:53
    
You need to close the div tag before the a href. The code would be: <div class="new-div"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></div></a> –  Jeremy Jared Aug 30 '11 at 0:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.