0

I've created a custom post type and taxonomy for a portfolio loop:

// Portfolio CPT
function portfolio_cpt() {
  $labels = array(
    'name'               => _x( 'Potfolio Items', 'post type general name' ),
    'singular_name'      => _x( 'Portfolio item', 'post type singular name' ),
    'menu_name'          => 'Portfolio Items'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Portfolio items',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
    'has_archive'   => true,
  );
  register_post_type( 'portfolio', $args ); 
}
add_action( 'init', 'portfolio_cpt' );

function portfolio_tax() {
  $labels = array(
    'name'              => _x( 'Portfolio Categories', 'taxonomy general name' ),
    'singular_name'     => _x( 'Portfolio Category', 'taxonomy singular name' ),
    'menu_name'         => __( 'Portfolio Categories' ),
  );
  $args = array(
    'labels' => $labels,
    'hierarchical' => true,
  );
  register_taxonomy( 'portfolio_category', 'portfolio', $args );
}
add_action( 'init', 'portfolio_tax', 0 );

This bit of code is in the single post page, so when I click a category, it sends me to the category archive page:

<?php

$taxonomy = 'portfolio_category';
$terms = get_terms($taxonomy);

if ( $terms && !is_wp_error( $terms ) ) :
?>
    <ul>
        <?php foreach ( $terms as $term ) { ?>
            <li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
        <?php } ?>
    </ul>
<?php endif;?>

And then created a custom archive file called archive-portfolio.php to list the posts relating to a specific category.

The problem is, it seems to be still using the default archive template, meaning I can't edit/style the page

Any ideas?

1

From what it sounds like, the archive for your "portfolio" custom post type works if it lists all portfolio posts, but if you click on your custom taxonomy within a post, it goes to the default archive.php.

Since this is custom taxonomy, it's not going to use your archive-portfolio.php because all that does is apply to the listing of all your portfolio posts, not their taxonomy. So what you likely need is a taxonomy template:

Custom Taxonomies Display on the Codex

If you look at the Template Hierarchy section on the Codex, you'll see that when WordPress gets to an archive - it looks for several files before defaulting to archive.php. That order is:

  1. taxonomy-{taxonomy}-{term}.php
  2. taxonomy-{taxonomy}.php
  3. taxonomy.php
  4. archive.php <-- Where you're defaulting because the above templates do not exist
  5. index.php

Hope that helps! :-)

  • @OllieRussell8 Great! Would you mind marking this as a correct answer if it solved your problem? There should be a checkbox under the number on my answer - upper right, if you're unfamiliar with stack exchange. Thanks. :-) – RachieVee Oct 24 '14 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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