WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category Archive Customization (5 posts)

  1. kanika
    Member
    Posted 1 year ago #

    Hi,

    I wrote the following code to customize a category-archive page. pretty simple. Just want it to loop through all posts and page if necessary.

    <?php
    				global $post;
    
    				$args = array('category' => 6, paged => '$paged');
    				$custom_posts = get_posts($args);
    				foreach($custom_posts as $post) :
    					setup_postdata($post);
    					the_content();
    				?>
    					<hr />
    				<?php
    				endforeach;
    				?>

    I can't figure out what is wrong with this 'cause it shows only upto 5 posts. If thats the default, then how much should I put it to to let pagination work?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Get rid of global $post;. Unless this is in a function, you don't need it. Try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array('category' => 6, paged => '$paged');
  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    for all posts, you would add this to your $args array:

    'posts_per_page' => -1

    http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

  4. kanika
    Member
    Posted 1 year ago #

    The second solution for all posts worked. But the pagination still isn't working( i.e. the first doln didn't work for me)

    If there is anything I can do about it, please tell me. My category archives sometimes look horrible when the reader has to scroll down too much.

    Another related question: The next post and previous post links can be customized to show the next post from that category only? Presently they show the next post according to date without caring about the category...
    Wanted to modify the category template a bit, bi uses
    get_template_part instead of a straight loop, so don't know how to do this...

  5. kanika
    Member
    Posted 1 year ago #

    Thanks for the solution provided. The link for the codex reference was also helpful.

    Thanks,
    Kanika

Topic Closed

This topic has been closed to new replies.

About this Topic