WordPress.org

Ready to get started?Download WordPress

Forums

problems with adding categories as links (1 post)

  1. giulia.munari
    Member
    Posted 1 year ago #

    Hi, I'm creating a template and I would like to add in a page categories as links and then as classes of a div, but the only part that goes well is the third query.

    Maybe the problem is that I've added 3 query_posts in the same loop:

    <?php if (is_page( 'Lavori' )) { ?>
             <?php if (have_posts()) : ?>
    
    <!-- html code -->
    
    <?php query_posts( 'category_name=media' ); ?>
                      <?php while (have_posts()) : the_post(); ?>
                      <?php $categories = get_the_category_list(); foreach($categories as $category): echo ('<li class="element_menu"><a class="link_gal transition" href="#'); echo $category->name; echo ('" data-filter-value=".'); echo $category->name; echo('">'); echo $category->name; echo('</a></li>'); endforeach;?>
    
                  <?php wp_reset_query();?>
     <?php endwhile; ?>
    
    <!-- html code -->
    
     <?php query_posts( 'category_name=lavorocliente' ); ?>
                    <?php while (have_posts()) : the_post(); ?>
    
                      <?php $categories = get_the_category_list(); foreach($categories as $category): echo ('<li class="element_menu"><a class="link_gal transition" href="#'); echo $category->name; echo ('" data-filter-value=".'); echo $category->name; echo('">'); echo $category->name; echo('</a></li>'); endforeach;?>
                    <?php endwhile; ?>
                   <?php wp_reset_query();?>
    
    <!-- html code -->
    
    <!-- here starts the only part that goes well -->
    <?php query_posts( 'category_name=item' );  ?>
    <!-- html code -->	
    
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    
    			<div style="overflow:hidden" class="moduli<?php $categories = get_the_category(); foreach($categories as $category):echo (' '); echo $category->name; endforeach;?>" id="post-<?php the_ID(); ?>">
    
        <?php endwhile; ?>
        <?php endif; ?>
        </div>
    </div>
    <?php } else { ?>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.