0

I have successfully created a custom taxonomy in WordPress, and I created a page that lists all of the posts under a specified taxonomy, with a file named taxonomy.php. It works, but some of the php isn't printing any text. The page seems to churn out some php errors with error reporting turned on:

Notice: Undefined variable: term_name in WEBSITE_ROOT/themes/starkers/taxonomy.php on line 24

The variable is $term_name. Here is the code I have in my taxonomy.php page. I followed this tutorial. I thought I followed the tutorial pretty well.

<?php

get_header(); ?>

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

            <h1><?php
                printf( __( 'Posts classified under: %s', 'starkers' ), '<span>' . $term_name . '</span>' );

            ?></h1>

            <?php
                $category_description = category_description();
                if ( ! empty( $category_description ) )
                    echo '' . $category_description . '';

            get_template_part( 'loop', 'category' );
            ?>


<?php get_footer(); ?>

Basically, it's not printing the taxonomy name after "Posts classified under:"

I tried fiddling around with the code, but no luck. If it helps, here is the code I used for functions.php to registering the taxonomy:

add_action( 'init', 'build_taxonomies', 0 );

function build_taxonomies() {
register_taxonomy(
    'quotees',
    'post',
    array(
        'hierarchical' => false,
        'label' => 'quotees',
        'query_var' => true,
        'public' => true,
        'rewrite' => true
    )
);
}
3
  • If you look in the comments, apparently $term_name should be $term->name. In fact, most of the $term_blahs should be $term->blah.
    – Blender
    Jul 15, 2012 at 4:28
  • That seemed to do the job. I had to also wrap some of the code in <?php ?> in order for it to work though. They should update that article! You can answer this question and I'll accept it if you want the credit.
    – davecave
    Jul 15, 2012 at 5:00
  • Could you edit those changes into your question (or just answer the question yourself, if you want)? Since the author of that post doesn't want to change his code, it's sort of misleading to people.
    – Blender
    Jul 15, 2012 at 5:02

1 Answer 1

0

If you look in the comments, apparently $term_name should be $term->name. In fact, most of the $term_blahs should be $term->blah.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.