WordPress.org

Support

Support » How-To and Troubleshooting » category post per page

category post per page

  • yortem
    Participant

    @yortem

    im using this code for post per page

    add_filter('pre_get_posts', 'limit_category_posts');
    function limit_category_posts($query){
        if ($query->is_category) {
            $query->set('posts_per_page', 5);
        }
        return $query;
    }

    but it makes foreach in the header.php also to be 5 post per page.
    the foreach is like this :

    <?php $catPost = get_posts(array('category'=>get_cat_ID( 'news' ),'numberposts'=>2)); ?>
    <?php foreach ($catPost as $post) : setup_postdata($post); ?>
    <div>
    content of post in the header
    </div>
    <?php endforeach; ?>

    what can ido?
    i want to posts in the header will be only 2 and every page in the category will be 5..

    hope you will understand.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘category post per page’ is closed to new replies.