Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$20
Custom Post Type - Single Template based on Taxonomy
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 single-wpcbd.php to give to my custom post type his personalized template.
I need to be able to have something like this single-wpcbd-restaurants.php 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
ellenica | 07/05/12 at 1:35am
Edit
Tutorial: How to assign prize money
(22) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
07/05/12
1:50amLuis Abarca says: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';
}
Previous versions of this answer: 07/05/12 at 1:50am
-

Last edited:
07/05/12
1:59amArnav Joy says: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. ?>Previous versions of this answer: 07/05/12 at 1:59am
-

Last edited:
07/05/12
1:48amScott Hack says:I think you want something like taxonomy-bd_categories.php or bd_categories_taxonomy.php I can't remember which way it is.
-

Last edited:
07/05/12
1:57amJatin Soni says: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>Previous versions of this answer: 07/05/12 at 1:57am
-

Last edited:
07/05/12
1:52amNavjot Singh says: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.Previous versions of this answer: 07/05/12 at 1:52am
-

Last edited:
07/05/12
1:55amHai Bui says: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 http://codex.wordpress.org/Template_Hierarchy -

Last edited:
07/05/12
2:07am -

Last edited:
07/05/12
2:33am -

Last edited:
07/05/12
6:25am -

Last edited:
07/05/12
6:48am -

Last edited:
07/05/12
7:03am -

Last edited:
07/05/12
8:42amdrewdelm says: -

Last edited:
07/05/12
8:49amluballneald says:- 07/07/12 2:17pm
luballneald says: - 07/07/12 3:06pm
luballneald says: - 07/07/12 4:14pm
luballneald says: - 07/07/12 5:08pm
luballneald says: - 07/07/12 7:40pm
luballneald says: - 07/08/12 12:53am
luballneald says:
- 07/07/12 2:17pm
-

Last edited:
07/05/12
9:05am -

Last edited:
07/05/12
1:26pmaburnamanperry says:- 07/06/12 1:17am
aburnamanperry says: - 07/07/12 8:41pm
aburnamanperry says:
- 07/06/12 1:17am
-

Last edited:
07/05/12
1:36pmlretaglemarge says:- 07/05/12 6:39pm
lretaglemarge says: - 07/05/12 9:24pm
lretaglemarge says: - 07/06/12 4:39am
lretaglemarge says: - 07/06/12 4:33pm
lretaglemarge says: - 07/07/12 4:40am
lretaglemarge says: - 07/07/12 10:47am
lretaglemarge says: - 07/07/12 3:21pm
lretaglemarge says: - 07/07/12 5:52pm
lretaglemarge says: - 07/07/12 7:39pm
lretaglemarge says:
- 07/05/12 6:39pm
-

Last edited:
07/05/12
5:35pmgspringmaange says:- 07/06/12 12:17am
gspringmaange says: - 07/06/12 4:44pm
gspringmaange says: - 07/07/12 3:00pm
gspringmaange says: - 07/07/12 7:21pm
gspringmaange says: - 07/07/12 7:39pm
gspringmaange says: - 07/07/12 11:18pm
gspringmaange says:
- 07/06/12 12:17am
-

Last edited:
07/05/12
11:35pmlbridalbridal says:- 07/06/12 8:14am
lbridalbridal says: - 07/06/12 9:13am
lbridalbridal says: - 07/07/12 9:09am
lbridalbridal says: - 07/07/12 3:45pm
lbridalbridal says: - 07/07/12 5:51pm
lbridalbridal says: - 07/07/12 8:03pm
lbridalbridal says: - 07/07/12 8:32pm
lbridalbridal says:
- 07/06/12 8:14am
-

Last edited:
07/06/12
1:28ameelardeselli says:- 07/06/12 1:29am
eelardeselli says: - 07/06/12 10:04pm
eelardeselli says: - 07/07/12 3:25pm
eelardeselli says: - 07/07/12 4:14pm
eelardeselli says: - 07/07/12 10:06pm
eelardeselli says: - 07/07/12 10:16pm
eelardeselli says:
- 07/06/12 1:29am
-

Last edited:
07/07/12
3:18pm -

Last edited:
07/07/12
8:45pm -

Last edited:
07/07/12
10:49pm
This question has expired.
Current status of this question: Community pot
Please log in to add additional discourse to this page.
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
