[resolved] Category Archive Customization (5 posts)

  1. kanika
    Posted 4 years ago #


    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.

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

    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 4 years 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. Michael
    Forum Moderator
    Posted 4 years ago #

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

    'posts_per_page' => -1


  4. kanika
    Posted 4 years 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
    Posted 3 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic