1
votes

I made a file as category-videos.php, since i read that either use category-[slug].php or category-[ID].php . But, i don't know the next steps. How to link it with wordpress ? How to link all posts with this template ?

Mainly my requirement is that I want to create a new template for my specific category "VIDEOS" so that all posts under this category show in new style. Basically, i want to show posts with videos in a new way as 3 posts in one row with featured images and a featured slider on top of that page showing 4 new posts of that category ?

But i am confused... Can i do this in wordpress ? Because my home page also has a featured slider. Can i create a new slider for that page template but one thing is sure. I need to work with only one category for that custom template i.e. videos.........

Any help will be appreciated. Thanks in advance ....

3
Please guide mainly for the steps to follow after creating the file, category-[slug].phpuser794573

3 Answers

1
votes

create a file category-[slug].php or category-[id].php - Put category's slug for which you want a different template in [slug] or its [id]. Wordpress provides this functionality by default.

See http://codex.wordpress.org/User:Lorelle/Custom_Category_Template for more information on this.

Another, not good approach is to use decision statements based on (is_category('id')) like

<?php if (is_category('ID')) : ?>
// Code For Category with defined ID
<?php else : ?>
// Code for else
<?php endif; ?>

but again this is not a good approach to use too much if else - also affects your server as well as each time server side decision will be taken to display content for if or else

0
votes

Create category-Id.php file (for example category-1.php). You can found Id number when hover on category in admin. You can do with this category what do you want.

For example, in my blog i have with thumbnail and without.

Another way via Is_category tag

<?php if (is_category('1')) : ?>
Code For Category One
<?php else : ?>
Code for other categories
<?php endif; ?>
0
votes

My custom template works just fine by adding slug or id ( category-slug.php ).. Wordpress will automatically find the right template according the template hierarchy. If you need the child of the category use the parent template too, use add_action('template_redirect','your_function').