WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts from category on main page (4 posts)

  1. blaze1
    Member
    Posted 6 years ago #

    Hi,
    I would like to display posts only from one specified category on main page. Is it possible in any way?

  2. BPartch
    Member
    Posted 6 years ago #

    Hello

    Yes just run query_posts above the loop.

    <?php query_posts('cat=#'); ?>

    cat=# should be changed to the cat you wish to display.

    This should go in index.php (or home.php if you are using it) like so:

    <?php if (have_posts()) : ?>
    
    <?php query_posts('cat=#'); ?>
    
    <?php while (have_posts()) : the_post(); ?>

    Hope it helps. :)

  3. blaze1
    Member
    Posted 6 years ago #

    Thank You very much, it works! but... when I click "older entries" nothing happens. Page reloads, then I see also link "newer entries", but posts are the same. It's not so important to me but it could be ok:)

  4. blaze1
    Member
    Posted 6 years ago #

    Ok, I've spend some time in reading docs, and I found it.
    Because if we use query_posts() GET variables doesn't work, and it should be define in query. So I made that query:

    <?php
    $query='cat=1&paged='.$paged;  // $paged is global variable
    
    if (have_posts()) :
    	if (is_home()) {
    		query_posts($query);
    		}
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic