2

I've made a custom taxonomy named activities, containing items named local, member, and national:

<?php
function add_custom_taxonomies() {
    register_taxonomy('Activities', 'post', array(
        'has_archive' => true,
        'hierarchical' => true,
        'labels' => array(
            // labels goes here
        ),
        'rewrite' => array(
            'slug' => 'activities',
            'with_front' => true, 
            'hierarchical' => true
        ),
    ));
}
add_action( 'init', 'add_custom_taxonomies, 0 );

And I've created each taxonomy item a page, which are taxonomy-activities-local.php, taxonomy-activities-member.php, and taxonomy-activities-national.php.

Accessing mydomain.com/activities/local/ is just fine. But accessing mydomain.com/activities/ itself redirects to a 404 page. I understand fully that this normally shouldn't work. It is just like accessing mydomain.com/tag/, which also redirects to a 404 page.

Is there a way to use a template PHP file that I made? Hence, accessing mydomain.com/activities/ uses that PHP file instead of the 404 page without using any plugins?

3
  • Create a page with slug activities?
    – Picard
    Commented Jul 16, 2017 at 17:28
  • You will need to read the developer.wordpress.org/themes/template-files-section/… taxonomy template article on WordPress.org for that information. Thanks.
    – Vishit
    Commented Jul 17, 2017 at 5:11
  • Have you tried to reset the permalink? I got that issue before and I just change the permalink to Plain and change back to Post name and it's no longer 404. Commented May 21, 2018 at 8:23

1 Answer 1

1

I think the best way to do it is to create a custom template page and get the list of terms (or whatever you need) on that template.

template-activities-taxonomy.php

<?php
/* Template Name: Activities Taxonomy */

get_header(); ?>

<?
$terms = get_terms( 'activities' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ): ?>
    <ul>
    <?php foreach ( $terms as $term ): ?>
        <li><a href="<?php echo esc_url( get_term_link( $term ) ); ?>"><?php echo $term->name; ?></a></li>    
    <?php endforeach; ?>
    </ul>
<?php endif; ?>

<?php get_footer(); ?>

And then just create a Page with the url you want (/activities) that uses that template.

0

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.