Hello,
i tray to explain, in my website i created a CUSTOM POST TYPE "wpcbd", and a CUSTOM TAXONOMY "bd_categories". Wordpress by default allow me to create a file <strong>single-wpcbd.php</strong> to give to my custom post type his personalized template.
I need to be able to have something like this <strong>single-wpcbd-restaurants.php</strong> i mean a custom template for all custom post type that are under custom taxonomy "restaurants" like is already possible withthe default post type and the default categories.
I'm becoming creazy because after 2 days of serach there are no doc or tutorial that explain this.
Thanks
Luis Abarca answers:
Try with
archive-bd_categories.php
----
Sorry, i misundertood the question above.
You can create 2 files in a folder named parts, one for normal files of any category and another one for restaurants.
So you can use single-wpcbd.php and change the content when you are showing a post from that category
<?php
// single-wpcbd.php
if ( has_term( 'restaurants', 'bd_categories', $post ) ) {
// you may also use get_template_part('loop', 'restaurants');
include 'parts/single-wpcbd-restaurants.php';
} else {
include 'parts/single-wpcbd.php';
}
Arnav Joy answers:
create a new file named as
taxonomy-bd_categories.php
and put following code there to list all the posts
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php endwhile; // end of the loop. ?>
Scott Hack answers:
I think you want something like taxonomy-bd_categories.php or bd_categories_taxonomy.php I can't remember which way it is.
Jatin Soni answers:
Try in this way to create page template
<?php
/*
TEMPLATE NAME: Your templatename
*/
//for a given post type, return all
$post_type = 'wpcbd';
$tax = 'bd_categories';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of '.$post_type . ' where the taxonomy '. $tax . ' is '. $tax_term->name;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();
}
}
?>
You can also try with this too
<?php
/*
TEMPLATE NAME: Your templatename
*/
query_posts( array( 'wpcbd' => 'bd_categories' ) ); ?>
<?php if( is_tax() ) {
global $wp_query;
$term = $wp_query->get_queried_object();
$title = $term->name;
} ?>
<ul>
<span class="tax-title"><?php echo($title); ?></span>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><?php the_excerpt() ?></li>
<?php endwhile; else: ?>
<?php endif; ?>
</ul>
Navjot Singh answers:
Try this:
add_filter( 'single_template', 'add_albumtrack_taxslug_template', 10, 1 );
function add_albumtrack_taxslug_template( $orig_template_path )
{
$object = get_queried_object();
if ( ! ( in_array( $object->post_type, array( 'wpcbd' )) && taxonomy_exists( 'bd_categories' ) && $album_tax = wp_get_object_terms( $object->ID, 'bd_categories' ) ))
return $orig_template_path;
$template = locate_template( $template );
return ( !empty( $template ) ? $template : $orig_template_path );
}
in your theme's function.php
And then you can create template files like single-wpcbd-restaurants.php where restaurant is a taxonomy of type bd_categories and wpcbd is your custom post type.
Hai Bui answers:
If you want to use a template for all taxonomy terms (under bd_categories), use taxonomy-bd_categories.php
If you want to use a template for a particular taxonomy term, for example "restaurants", use taxonomy-bd_categories-restaurants.php
For more information about WP template hierarchy, you can check this [[LINK href="http://codex.wordpress.org/Template_Hierarchy"]]http://codex.wordpress.org/Template_Hierarchy[[/LINK]]
yehallystevi answers:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
yehallystevi comments:
luballneald answers:
luballneald comments:
luballneald comments:
luballneald comments:
luballneald comments:
luballneald comments:
luballneald comments:
lretaglemarge answers:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
lretaglemarge comments:
gspringmaange answers:
gspringmaange comments:
gspringmaange comments:
gspringmaange comments:
gspringmaange comments:
gspringmaange comments:
gspringmaange comments:
lbridalbridal answers:
lbridalbridal comments:
lbridalbridal comments:
lbridalbridal comments:
lbridalbridal comments:
lbridalbridal comments:
lbridalbridal comments:
lbridalbridal comments:
eelardeselli answers:
eelardeselli comments:
eelardeselli comments:
eelardeselli comments:
eelardeselli comments:
eelardeselli comments:
eelardeselli comments: