WordPress.org

Ready to get started?Download WordPress

Forums

Show category once in a loop (9 posts)

  1. katalonian
    Member
    Posted 3 years ago #

    Hi everybody. I want to show category name once in Loop. There is a code: http://codepad.org/9it99CUn

    I'm showing child of category. How to show cat name once? Thanks! Hope to get answer soon.

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    with a counter : http://codepad.org/kgQMBqEh

  3. katalonian
    Member
    Posted 3 years ago #

    Thank for you answer soo much!
    But, it's doesnt work for me( Showing same. Can you explain how its works?

  4. wprock
    Member
    Posted 3 years ago #

    what will be the output? can you give a demo?

  5. katalonian
    Member
    Posted 3 years ago #

    Sure:
    http://artstore.az/sultan/our-menu/

    Click to first column (Меню еды)
    How you can see, the expandable box name is child cat name, and i want tp show that once.

  6. wprock
    Member
    Posted 3 years ago #

    try once

    <?php  $cats = get_the_category('cat_name=food_menu');
           foreach($cats as $c):?>
    <li>
                                    	<div class="item"><span><?php echo $c->cat_name;?></span></div>
    <?php query_posts('category_name=' . $c->cat_name);
    				if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
                                            <ul style="display:none">
                                              <li>
                                              	<div class="left_block">
                                                    <div class="name"><span><?php the_title (); ?></span></div>
                                                    <div class="text"><span><?php the_content (); ?></span></div>
                                                </div>
                                               	<div class="price"><span><?php the_excerpt (); ?></span></div>
                                                    <div class="cb"> </div>
                                              </li>
                                            </ul>
    
    								 <?php endwhile; wp_reset_query ();?>
    <div class="cb"> </div>
                                    </li>
    <?php endforeach;?>

    Modified

  7. katalonian
    Member
    Posted 3 years ago #

    Thank you for try, but doesn't work at all( Box just disappear. Can you offer in another way? and pls don't forget that i'm using child cat name in expand box.

  8. wprock
    Member
    Posted 3 years ago #

    replace $cats = get_the_category('cat_name=food_menu');

    with

    $cats = get_categories('child_of=3&hide_empty=0');

  9. katalonian
    Member
    Posted 3 years ago #

    OK. Now! It's working, but, the posts are showing by one too (( I need to show once only cat names.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags