Title: Archive.php loop
Last modified: June 11, 2022

---

# Archive.php loop

 *  [gabrixbr](https://wordpress.org/support/users/gabrixbr/)
 * (@gabrixbr)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/archive-php-loop/)
 * Hello Héctor!
 * Is there a way to (pre) filter popular posts according to WordPress hierarchical
   template files (like category.php or archive.php). I know that it can be done
   by shorcode or PHP (WP_Query), but I wanna know if is there a way to accomplish
   it “automatically” in template files…
 * Thanks in advance for the great plugin!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/archive-php-loop/#post-15728013)
 * Hi [@gabrixbr](https://wordpress.org/support/users/gabrixbr/),
 * Well, not really. You’ll always need to do some level of custom coding if you
   want to change how archive pages (category, tag, etc) work.
 * For example, let’s say that you want your category.php template to be sorted 
   by views count (which is I guess the whole reason why you opened this topic haha).
   In that case I’d follow the first step from the [How To: Sorting a custom query by views (All time, monthly, weekly, or daily)](https://wordpress.org/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/)
   tutorial, then use the [pre_get_posts hook](https://developer.wordpress.org/reference/hooks/pre_get_posts/)
   to sort posts by a views meta field (see [order & orderby parameters](https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters)),
   like ‘views_daily’) for example, and that’s that.
 *  Thread Starter [gabrixbr](https://wordpress.org/support/users/gabrixbr/)
 * (@gabrixbr)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/archive-php-loop/#post-15728701)
 * Thank you Héctor,
    I’m going to try it..

Viewing 2 replies - 1 through 2 (of 2 total)

 The topic ‘Archive.php loop’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [gabrixbr](https://wordpress.org/support/users/gabrixbr/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/archive-php-loop/#post-15728701)
 * Status: not resolved