WordPress.org

Forums

category post per page (3 posts)

  1. yortem
    Member
    Posted 1 year ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

  3. Michael Beckwith
    Member
    Posted 11 months ago #

    delete my post here. posted to wrong thread.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.