This is the setup I want:

For category-15.php:

 Child Category A (list of all posts inside)
     Post A from Child Category A
     Post B from Child Category A
     Post C from Child Category A
 Child Category B (list of all posts inside)
     Post A from Child Category B
     Post B from Child Category B

And for ALL child categories under category-15, I want them to display:

Child Category Title (paginated with 2 posts each)
     Post A
     Post B

As I understand, WordPress does not have something like:

category-15.php (for parent)

category-15-child.php (for children)

Right now, I have a query in my category-15 that checks if the category has children (if yes, display the code for the parent; if no, display code for children).

Is there a cleaner and faster way to do this?

  • 1
    There's nothing wrong with the way you've done it. It's a great solution to your problem. – deflime Jul 18 '14 at 5:30
  • 1
    @Anon you can have 100 queries more, as long as they are time efficient. You'll need to look at how much longer does it take to run these extra queries. How time efficient are your queries. If the impact is absolute minimal, why worry about that. On the other hand, look for an alternative if these queries have a big negative impact on time. – Pieter Goosen Jul 18 '14 at 6:17
  • 2
    @Anon Download and install Query Monitor. This will print all queries and how efficient are they, so you will be able to see how fast a query is executed. This will also tell you immediately if a query is taking to much time. Just don't use it on a production site – Pieter Goosen Jul 18 '14 at 6:27
  • 1
    I don't know if this will help you out at all but this is how I declare pagination in WP_Query: 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1; – deflime Jul 18 '14 at 6:27
  • 1
    This plugin is for development purposes only, and really has no other use than that. You really don't want to run this unnecessary – Pieter Goosen Jul 18 '14 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.