Include the Taxonomy name on Archive pages

Hi,

I am looking for a solution to include a txonomy term on the archive pages such as http://handheld.simplecsr.com/calories/1000-1500/

Currently these use the default index.php page and have the static code:

<div class="main_category_title">
<h1>Category: <?php single_cat_title(); ?></h1>
</div>

1. I would like to find a way to replace the static word "Category: " with the taxonomy name. In this example "Calories: "

2. I am using the same index.php page for blog post and my new content type of Walks.

How do I get my new Content Type of "Walks" to use its own index file? What do i need to name it?

(I am using a child theme for all these changes)

Many thanks
Chris

  • Michael Bissett

    Hey @chris, hope you're doing well today. :slight_smile:

    1. You can try inserting this after get_header:

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

    And then replace "Category" with this:

    <?php echo $term->name; ?>

    2.

    How do I get my new Content Type of "Walks" to use its own index file? What do i need to name it?

    Are you wanting an index file (template) for single posts, or for archives? It looks like you've already got a "single" template for the "Walks" template?

    Please advise,
    Michael

  • chris

    Hi Michael,

    That code replaced Category: with a duplicate of the Term name. (same as <?php single_cat_title(); ?>

    I need it to identify the taxonomy name (Duration, Distance, Calories, Amenities etc)

    Any ideas?

    As for the custom template it is needed for the archive.

    I have a custom single_walk.php template for individual walks but I wanted something for archives for the taxonomies that are used only for walks.

    So for example my taxonomines of distance, duration, calories and amenities are only used for the content type Walks.

    It may be possible to get away without using a custom archive template page for this job - but i have some other site i was hoping to completely customise the archive pages of the custompress new content types.

    Thanks
    Chris

  • Ash

    Hi @chris

    I hope you are well today.

    Would you please try the following instead of $term->name?
    <?php echo $term->taxonomy; ?>

    About the custom template, is "Walks" a custom post type? Then you can create your custom template based on this post type:

    For single: single-walks.php
    For archive: archive-walks.php

    If it is a custom taxonomy: taxonomy-walks.php

    If it is a tag: tag-walks.php

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.