• Good afternoon, community, okay, I have the following problem.

    I have a single.php in this single contains the header, footer and template part called nav-category.php

    So far so good, inside my template_part I put the following function, wp_list_categories, to display all categories.

    But when I run my single it is only bringing in my template part of the post category, in fact I want it to bring me all the posts.

    What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The wp_list_categories() should display all categories all the time regardless of the current page/post. Could you copy / paste the code you’re using for wp_list_categories()?

    My code

    <?php include('header.php'); ?>
    	<div class="banner">
    		<div class="container">
    			<div class="row">
    				<div class="col-lg-6">
    					<h2>Acompanhe todas as noticias</h2>
    				</div>
    				<div class="col-lg-6">
    					<img />/image.jpg" alt="">
    				</div>
    			</div>
    		</div>
    	</div>
    
    	<section class="single">
    		<div class="submenu">
    			<div class="container">
    				<div class="row">
    					<div class="col-lg-12">
    						<nav>
    							<?php wp_list_categories();?>
    						</nav>	
    					</div>
    				</div>
    			</div>
    		</div>
    
    		<div class="container">
    			<div class="row">
    				<div class="col-lg-12">
    					<div class="breadcrumb">
    						<?php get_breadcrumb();?>
    					</div>
    					
    					<?php if ( have_posts() ) : ?>
    					    <?php while ( have_posts() ) : the_post(); ?>
    					       <?php the_title('<h3>','</h3>');?>
    					       <?php the_post_thumbnail('single_posts', ['class' => 'svg-clippedsingle']);?>
    					       <?php echo 
    					       			'<svg>
    										<defs>
    											<clipPath id="svgsingle">
    												<path fill="#000" d="M0,0v167.373v0.376v277.923h1099.867c20.564,0,34.156-15.344,36.887-37.82l0.055-0.925V0H0z"/>
    											</clipPath>
    										</defs>
    									</svg>'
    					       		;
    					       	?>
    					       	<?php the_content();?>		
    					    <?php endwhile; ?>
    					<?php endif; ?>
    										
    				</div>
    			</div>			
    		</div>		
    	</section>
    
    	<div class="posts">
    		<div class="container">
    			<div class="row">
    				
    				<?php
    					$args = array(
    						'cat' => 1,
    						'post_per_page' => 2
    					); 
    					$the_query = new WP_Query( $args ); ?>
    					<?php if ( $the_query->have_posts() ) : ?>
    						<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    							<div class="row notices">
    								<div class="col-lg-5">
    									<?php the_post_thumbnail('posts_anteriores', ['class' => 'svg-clipped img-responsive']);?>
    									<svg>
    										<defs>							
    											<clipPath id="svgPath">
    												<path fill="none" d="M0,0v103.822v0.377v37.82h322.058c20.564,0,34.156-15.346,36.887-37.82h0.055V0H0z"/>
    											</clipPath>
    										</defs>
    									</svg>
    								</div>
    								<div class="col-lg-5">
    									<?php the_title('<h3>','</h3>');?>
    									<a>" title="<?php the_title_attribute();?>" class="btnsimple">Leia Mais</a>
    								</div>
    							</div>
    						<?php endwhile; ?>
    						<?php wp_reset_postdata(); ?>
    					<?php else : ?>
    						<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
    					<?php endif; ?>
    				<div class="col-lg-12">
    					<hr>
    				</div>
    			</div>
    		</div>
    	</div>
    	
    	<section class="projetos">
    		<div class="container">
    			<div class="row">
    				<div class="col-lg-4">
    					<a href="">
    						<img />/images/banner-influenza.png" class="bninfluenzap">
    					</a>
    				</div>
    				<div class="col-lg-8 text-center brand">
    					<h3>Conhe?a os projetos de apoio à exporta??o de proteínas brasileiras</h3>
    					<a href="https://www.brazilianpork.com.br/en" title="Brazilian Pork">
    						<img />/images/logotipo-brazilian-pork.svg" alt="Brazilian Pork" class="img-responsive">
    					</a>
    
    					<a href="https://" title="Brazilian Chicken">
    						<img />/images/logotipo-brazilian-chicken.svg" alt="Brazilian Chicken" class="img-responsive">
    					</a>
    
    					<a href="https://" title="Brazilian Egg">
    						<img />/images/logotipo-brazilian-egg.svg" alt="Brazilian Egg" class="img-responsive">
    					</a>
    				</div>
    			</div>
    		</div>
    	</section>
    
    <?php include('footer.php');?>
    Moderator bcworkz

    (@bcworkz)

    When I use your template code, I get all categories listed. Are you sure you are seeing output from this template? If you add “Hello world!” to the template, does it show up on a single post page?

    It’s possible for other code to alter what wp_list_categories() does. Try deactivating all plugins. Do you get all categories now? If so, one of those plugins was altering the function. If not, your theme is altering output for some reason.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function wp_list_categories not Working’ is closed to new replies.