5

I'm making website about movies. Taxonomy is using to for a cast. For example:

enter image description here

Cool yeah? :D But i want to show the description on this page. I'm talking about this: enter image description here

How to make it? Here is a code of taxonomy.php:

    <?php get_header(); ?>

<div class="module">
    <?php get_template_part('inc/parts/sidebar'); ?>
    <div class="content">


    <header><h1><?php printf( __( '%s', 'mundothemes' ), '' . single_tag_title( '', false ) . '' ); ?></h1></header>
    <div class="<?php if(is_tax('dtquality')) { echo 'slider'; } else { echo 'items'; } ?>">
        <?php if (have_posts()) :while (have_posts()) : the_post(); ?>
            <?php  if(is_tax('dtquality')) { get_template_part('inc/parts/item_b'); } else { get_template_part('inc/parts/item'); } ?>
        <?php endwhile; endif; ?>
    </div>
<?php if (function_exists("pagination")) { pagination($additional_loop->max_num_pages); } ?>
    </div>
</div>
<?php get_footer(); ?>
dawidurusek
  • 113
  • 1
  • 1
  • 11

6 Answers6

7

That should work with <?php echo term_description(); ?>

see also https://codex.wordpress.org/Function_Reference/term_description, where you can also read about the two optional parameters $term_idand $taxonomy

Johannes
  • 64,305
  • 18
  • 73
  • 130
1

You can use the method term_description

echo term_description($term_id, "your-taxonomy");

Valdeir Psr
  • 702
  • 1
  • 7
  • 10
1

Every taxonomy has a unique id, like "course_teachers". so we grap it like :

get_the_terms($post->ID , 'course_teachers');

In this example we are graping the first term of ower taxonomy and store it inside a variable. like :

$course_teacher = get_the_terms($post->ID , 'course_teachers')[0];

now we need to grap the description :

$teacher_description = term_description( $course_teacher, 'course_teachers' );

Finally, print the description on the web page :

echo $teacher_description;

Note: if you get an error like (variable $post not exist). don't worry, just add code below on top of your code :

global $post;

If you are using a "loop". you need to write the $teacher_description variable inside the loop.

Grap other data's :

-> taxonomy name

$teacher_name = $course_teacher->name;

-> taxonomy archive URL

$teacher_archive_url = get_term_link( $course_teacher, 'course_teachers' );

I'm not a backend developer and it's was all of my knowledge. I hope this will help someone.

babakfp
  • 164
  • 6
0

123 is term id.

$data = get_term(123)->description;
print_R($data);
4b0
  • 21,981
  • 30
  • 95
  • 142
0

Display category description:

        <?php
          the_archive_description( '<div class="taxonomy-description">', '</div>' );
        ?>

https://developer.wordpress.org/reference/functions/the_archive_description/

Nuno Sarmento
  • 415
  • 5
  • 15
0

This one worked for me to display the taxonomy description.-

<?php echo get_the_archive_description(); ?>