Support » Fixing WordPress » Category Archive Customization

  • Resolved kanika

    (@kanikawordpresscom)


    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?

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

    (@esmi)

    Forum Moderator

    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');
    Michael

    (@alchymyth)

    Forum Moderator

    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

    kanika

    (@kanikawordpresscom)

    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…

    kanika

    (@kanikawordpresscom)

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

    Thanks,
    Kanika

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Category Archive Customization’ is closed to new replies.