WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Head of sidebar post - diplicated (3 posts)

  1. toto
    Member
    Posted 6 years ago #

    Hello to all friends. Pls help. I want to show header for block of posts, and the header will be visible only if have posts in catecory. How to make it.

    example: in my sidebar i call some posts from cat4
    backticks
    <?php query_posts('cat=4&showposts=3'); ?>
    <ul.><?php while (have_posts()) : the_post(); ?>
    <.li>"><?php the_title(); ?></li.><?php endwhile;?></ul.>
    backticks

    i thing the code may look like this:
    backticks

    <?php query_posts('cat=4&showposts=3'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2>Section header</h2><.ul>
    <.li>"><?php the_title(); ?></li.><?php endwhile;?></ul.>backticks

    but if i use this code, the header and the ul tag is duplicated!?

    So how to set header that will NOT be duplicated and NOT be visible if cat4 dont have any posts?

    pls help and many thanks

  2. yoyo
    Member
    Posted 6 years ago #

    <?php query_posts('cat=4&showposts=3'); ?>
    	<?php if (have_posts()) : the_post(); ?>
    		<h2>Section header</h2>
    	<?php endif; ?>
    
    <?php query_posts('cat=4&showposts=3'); ?>
    <ul>
    	<?php while (have_posts()) : the_post(); ?>
    		<li><?php the_title(); ?></li>
    	<?php endwhile;?>
    </ul>
  3. toto
    Member
    Posted 6 years ago #

    thanks a lot :)

Topic Closed

This topic has been closed to new replies.

About this Topic