2
In my file category.php I have a layout where I have a side menu where the subcategorias of categoria current and a <section></section> where the current posts should be displayed categoria and subcategoria, to generate the menu with subcategorias of categoria current I did:
$categories = get_categories('child_of='.get_the_category()[0]->term_id);
<nav class="panel">
<?php foreach($categories as $category): ?>
<a href="<?= get_category_link($category->term_id); ?>" class="panel-block">
<?= $category->name; ?>
<span class="icon"><i class="fa fa-angle-right fa-fw"></i></span>
</a>
<?php endforeach; ?>
</nav>
In the section i made:
<?php query_posts('posts_per_page=-1&cat='.get_the_category()[0]->term_id); ?>
<?php if (have_posts()): while(have_posts()): the_post(); ?>
<article class="column is-half">
<div class="price-label">
<div class="price-title">
<h1 class="title is-6">0001. <?php the_title(); ?></h1>
<h2 class="subtitle is-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis.</h2>
</div>
<div class="price-tag has-text-right">
<p><span class="size">P</span> <small>R$</small> 21.90</p>
<p><span class="size">M</span> <small>R$</small> 25.90</p>
<p><span class="size">G</span> <small>R$</small> 35.90</p>
</div>
</div>
</article>
<?php endwhile; endif; ?>
I can’t get her to section always take the posts of the current page being her categoria or subcategoria, I can only catch the categorial current using get_the_category()[0]->term_id, and don’t know how to pick up the posts of the current subcategoria, how can I make posts is displayed according to the current categoria or subcategoria?
By the way: https://naousequeryposts.wordpress.com/
– Ricardo Moraleida
Thanks Ricardo, when I try to assemble the menu I would like to always pick the category
pai(main) because when I access the subcategories of the way I am writing I receive aarrayempty, I’m trying to useget_the_category()but I always get one backarrayemptiness as well.– RFL
get_the_categoryserves to search for categories associated with a specific post. If you want to know the category of the template, usesingle_term_title()to take the title orget_queried_object()to get the current object of the query.– Ricardo Moraleida