WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query for current category with paging? (4 posts)

  1. heidekeal
    Member
    Posted 1 year ago #

    Hello,

    I build a wordpress website and build the theme completely myself. The website uses 10 categories. Each post is placed in one of the categories so i have one categorie that displays all posts. The other categories are for displaying a specific category.

    Because off a lot of posts i added paging... but the problem is that each category now displays all the posts. I think because of a query problem. I need a query with paging that displays only the posts of the current category.

    i use the following code before the standard loop code:
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5'.'&paged='.$paged);

    ?>

    i hope someone have a suggestion!

    greetz

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    is there a reason why you set the number of posts per page directly in the template (category.php ?) and not from the dashboard - settings - reading - blog pages show at most ... ?

    try (has to be in category.php):

    $wp_query->query('showposts=5&cat='.get_query_var('cat').'&paged='.$paged);
  3. heidekeal
    Member
    Posted 1 year ago #

    Hello,

    Thanx for your fast solution! I tried and it works well! i use it in the archive.php and works very well now thanx again! There was no reason for the number of posts but i find it in a tutorial, thats why i use the code! I understand that put it in the settings is enough and you don't need te showposts=5..?

    greetz!

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    I understand that put it in the settings is enough and you don't need te showposts=5..?

    exactly - as matter of fact, you won't need the query code at all, as a category archive would automatically query the right posts (with pagination).

    review http://codex.wordpress.org/Theme_Development

Topic Closed

This topic has been closed to new replies.

About this Topic