Suporte » Desenvolvendo com WordPress » Lsitar Categorias e Posts

  • galera tem como eu montar um estrutura onde os posts venham da seguinte forma em uma página?

    Categoria
    – Nome Sub Categoria
    Post
    Post
    Post
    – Nome Sub Categoria
    Post
    Post
    Post

    eu consigo ver da seguinte forma

    -Categoria
    Posts
    Posts
    Posts

    ou

    -SubCategoria
    Posts
    Posts
    Posts

Visualizando 1 resposta (de um total de 1)
  • Fiz aqui e deu certo:

    <?php
    	$categories = get_categories( array( 'parent' => 0 ) );
    
    	foreach( $categories as $category ) :
    		echo "<br>Cat: " . $category->name;
    
    		$subcategories = get_categories( array( 'parent' => $category->term_id ) );
    
    		foreach( $subcategories as $subcategory ) :
    			echo "<br>Sub: " . $subcategory->name;
    			$posts = new WP_Query( array( 'cat' => $subcategory->term_id ) );
    
    			while($posts->have_posts()) : $posts->the_post();
    				echo "<br>Post: "; the_title();
    			endwhile;			
    
    		endforeach;
    	endforeach;
    ?>
Visualizando 1 resposta (de um total de 1)
  • O tópico ‘Lsitar Categorias e Posts’ está fechado para novas respostas.