WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using query_posts function disables page view (3 posts)

  1. StoarceCreierul
    Member
    Posted 4 years ago #

    I am using query_posts function to show posts from only one category on my home page. By doing this, the blog pages show only the first page. So if the adress is http://www.my*site.com/page/3/ the page shows the exact same thing as in http://www.my*site.com/.

    I use this function inserted in index.php right after the header:

    <?php get_header(); ?>
    
    <!-- Showing posts from category 3 alone: -->
    <?php
          query_posts("cat=3");
    ?>
    
        <div id="content">
    
            <div id="main">
    
    <!-- the rest of index.php -->

    Is there a way to fix this? Or maybe another way to show posts from only one category on the main page and having subpages working?

  2. MichaelH
    Member
    Posted 4 years ago #

    Example of proper pagination:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=3&posts_per_page='.get_option('posts_per_page').'&paged=' . $paged);
    ?>

    See WordPress Default theme's wp-content/themes/default/index.php for example of using the template tags, previous_posts_link() and next_posts_link().

  3. StoarceCreierul
    Member
    Posted 4 years ago #

    Right on. Thank you sir!

Topic Closed

This topic has been closed to new replies.

About this Topic