Skip to main content
added 6 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-txtv.php, etc).

If you don't need a full template file and only need small modifications, like differents CSS classes, you can check if the post has the term and assign a diferrent class. For exmaple, in a common single template:

 <div class="<?php echo class="<?php echo has_term( 'radio', 'type' ) ? 'radio' : ''; ?>">
   <?php the_cotent();?>
</div>

Or

<?php
$terms = get_the_terms($post->ID, 'type');
$class = '';
//Make a foreach because $terms is an array but it supposed to be only one term
foreach($terms as $term){
    $class = $term->slug;
}
?>
<div class="<?php echo $class; ?>">
   <?php the_cotent();?>
</div>

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tv.php, etc).

If you don't need a full template file and only need small modifications, like differents CSS classes, you can check if the post has the term and assign a diferrent class. For exmaple, in a common single template:

 <div class="<?php echo class="<?php echo has_term( 'radio', 'type' ) ? 'radio' : ''; ?>">
   <?php the_cotent();?>
</div>

Or

<?php
$terms = get_the_terms($post->ID, 'type');
$class = '';
//Make a foreach because $terms is an array but it supposed to be only one term
foreach($terms as $term){
    $class = $term->slug;
}
?>
<div class="<?php echo $class; ?>">
   <?php the_cotent();?>
</div>
added 6 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

deleted 23 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

This code should bePut this in the functions.php file of ayour theme or in a plugin. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

This code should be in the functions.php file of a theme or in a plugin. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

added 6 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
edited body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
added 167 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading