I would like to have a custom post type which contain several sliders for showing in each category page (exact category.php), one for each as planned.
All sliders were assigned to related category.
Currently I am using http://wordpress.org/plugins/custom-post-type-ui/ to create a custom post type called: slider.
And I am having the below code for showing all posts from a category while pressing the cat name in menu. It works fine of course.
<?php $cat = get_the_category(); $cat = $cat[0];ã?>
<?php query_posts($query_string . '&cat='. $cat->cat_ID .''); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
But the problem is I can’t filter the slider (custom post type) by category.
Once I call the wp_query
, it rolls out all the sliders and ignores my get cat id arg.
Thought it should show only the slider in certain category, not all category.
So I am asking for a query to call the right slider only.
I have worked out on your problem and have come up with a solution(as far I have understood the problem).
It’ works like this:
Registering a post type called : sliders with a taxonomy called slider.
This will create a post type where you can store all your sliders and categories them with this custom taxonomy called slider.
CODE for registering the post type. (this goes in functions.php)
Now as I have created the post type which will collect all the posts related to different sliders. Now the next step is to create a custom page which can show these posts based on their taxonomy selected. The best way to show is to create a taxonomy-slider.php in theme’s directory. This page will automatically catch posts based on slider categories.
Create taxonomy-slider.php and paste this code:
Customize it the way you like.
NOTE: AFTER ALL THE STEPS. Visit Settings > Permalinks page. This will save the changes made by registering custom post type.