0

This question is for a very specific refinement on the use of WordPress template files. The refinement would work similarly to how default archive.php and variants work, but we would like to have a second template that has the same mechanism for querying the desired category through the link address.

The model is a wood site where some people like to browse through the default template style, but others would prefer to just see a list of links.

The goal is to create one template where the category would be passed to the template through the link, instead of having to create a new list template for each category.

1

Why not using a meta field ? That way you can determine which template to use for specific category template.

In your loop just get the current category that you are trying to load:

if( have_posts() ) {
while( have_posts() ) {

    the_post();
    $meta_value = get_post_meta( get_the_ID() , 'meta-field', true );

    if($meta_value == 'template1') { 
         //I prefer using this method. Create folder templates with file content-template1.php where you can design your content. That way it is way more clear.
         get_template_part('templates/content','template1');
         // or you can use this method
         the_title();
    }

}

// Very Important
wp_reset_postdata();
}
| improve this answer | |
  • This may not be precisely the answer, but I think an adaptation will work. – Nora McDougall-Collins May 12 at 16:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.