Forums

[resolved] List all posts by month (16 posts)

  1. projectdesigns
    Member
    Posted 4 years ago #

    when a user clicks on a archive link (example: July 2007) I want it to display all the posts made in July 2007. Right now it will only display the number I have set under options for how many posts to display on the homepage (which in my case is 1)

    How do I do this?
    thanks

  2. Adam Brown
    Member
    Posted 4 years ago #

    Enjoy:

    http://codex.wordpress.org/Template_Tags/query_posts

    (look for "showposts" if I remember right)

  3. projectdesigns
    Member
    Posted 4 years ago #

    If I do the query_post thing and add showposts=-1 it gives me all of the posts i have ever written. I want it to just give me the posts that go with what ever month/year the user selects.

    Please walk me through this I have been trying to do this for a while.

  4. projectdesigns
    Member
    Posted 4 years ago #

    Here is my archive.php code if someone could point out what to do and where to do it.

    <?php get_header(); ?>
    
    <!--Begin Loop-->
    <?php if (have_posts()) : ?> 
    
     <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    <?php /* If this is a category archive */ if (is_category()) { ?>
    		<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
    
     	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
    
    	 <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2>
    
    		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
    
    	  <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    		<h2 class="pagetitle">Author Archive</h2>
    
    		<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    		<h2 class="pagetitle">Blog Archives</h2>
    
    		<?php } ?>
    
    		<div class="pagination">
    			<div class="alignleft"><?php next_posts_link('&laquo; Previous Articles') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Articles &raquo;') ?></div>
    		</div>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <h3 class="catArch_title"><a href="<?php the_permalink(); ?>" class="title"><?php the_title(); ?></a><br />
    <span class="catArch_date">Posted in <?php the_category(', '); ?> on <?php the_time('F, jS, Y') ?></span>
    </h3>
    
    <!--End Loop-->
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <div class="pagination">
    			<div class="alignleft"><?php next_posts_link('&laquo; Previous Articles') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Articles &raquo;') ?></div>
    </div><br />
    
    </div>
    
    <?php get_sidebar(); ?><br />
    <?php get_footer(); ?>
  5. Adam Brown
    Member
    Posted 4 years ago #

    You would need more parameters than just showposts. Take a look at the other parameters too.

  6. projectdesigns
    Member
    Posted 4 years ago #

    I have I can't figure it out, I have tried month and year not luck, I really don't know what to do.

  7. projectdesigns
    Member
    Posted 4 years ago #

    Alright I can get it to show all the posts in the current month so like right now even if i click on July 2007 it will show me all the posts made in October 2007. How do I set the monthnum and year parameters to be what they user clicked on?

  8. moshu
    Member
    Posted 4 years ago #

    Why don't you just use the Custom Query String plugin so that you can set the number of posts shown for every kind of "view"
    index/home, categories, cat by name, serach, tags, month etc.

  9. projectdesigns
    Member
    Posted 4 years ago #

    Ok i got and activated that plugin but I still dont know where to set the number of posts. Can some one just give me a straight answer I'm really tired of trying to get this to work.

  10. moshu
    Member
    Posted 4 years ago #

    What can be straighter than clicking on Options > CQS????

  11. projectdesigns
    Member
    Posted 4 years ago #

    oh I did not see that, yeah Ok that's easy I set is_archive show -1 posts order by date.

    Still only showing one post when I click on a month/year. So when i click on october 2007 it will show one post, I can click previous posts but it only shows one post per page I want it to show all the posts for that month/year. I am using a theme that I created could that be the problem?

  12. moshu
    Member
    Posted 4 years ago #

    That could be very much a problem. It can also be a problem if you messed around with the Loop code in your templates (adding query_posts and whatnot)... and you did NOT remove all that stuff.

    And set is_month to whatever number you want!

  13. projectdesigns
    Member
    Posted 4 years ago #

    Ok i got it working, under reading options I had it show at most 1 post set. I did this so only 1 post would show on the home page. So I changed that to -1 and then added a is_home to the CQS and made that 1 post.

    Now it shows all the the posts for the archives, and only one post for the home page.

    Awesome everything works. Great plugin thanks for the help.

  14. moshu
    Member
    Posted 4 years ago #

    Glad it worked for you!
    Could you, please, set this topic as "resolved"? (upt below the title)

  15. nlaspf
    Member
    Posted 4 years ago #

    I know this is solved already, but I had the exact same problem today and made it work without a plugin. Use this:

    query_posts($query_string."&posts_per_page=-1")

    By using $query_string you are keep the original query (all posts in a particular month), and then adding the posts_per_page parameter to it. If you don't add that, what you're doing is replacing the original query for a new query with whatever parameters you use.

  16. kerunt
    Member
    Posted 4 years ago #

    nlaspf, thanks for the code! Exactly what I was looking for.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags