Loop from the Wordpress category

0

I'm trying to loop only from the category I'm on Wordpress and I'm not getting it. Someone give me a light? I'm trying the archive.php file for the theme.

You should only see posts in the open category.

Below the code for my archive.php:

<?php
if (is_home()){
query_posts("showposts=5&cat=1,2,3,4,5,6,7,8,9,10,11,12"); while(have_posts()) : the_post(); ?>
<div class="LatestPosts">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<div class="TxtNotice">
<?php //echo excerpt('20'); ?> <?php  echo the_title(); ?>[...]
</br>

</a>
</div>
<?php 
endwhile; wp_reset_query(); }?>
    
asked by anonymous 27.12.2016 / 23:45

2 answers

1

In fact wordpress it will recognize the category.php file by default to display the posts of a category, just put the following code:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<!-- DADOS DOS POSTS AQUI -->

<?php endwhile; endif;?>

After this when clicking on a category wordpress will call this page and already send the category as a parameter for it, thus displaying the posts of a certain category.

I hope to help you.

    
03.01.2017 / 12:24
0

Felipe, what you are looking for is get_queried_object ();

It fetches the object in question.

Or, declaring the $ post as global and returning the category:

global $post;
$postcat = get_the_category( $post->ID );

This filters your posts only by the variable $ postcat;

Note that you can always use var_dump () to be aware of the results.

For example, when using:

  

global $ post;   $ postcat = get_the_category ($ post-> ID);

You can give a var_dump ($ postcat); And check the value you returned, if that's what you need, solved problem:)

    
18.02.2018 / 19:11