Custom post url structure with tags and tag listing

Asked

Viewed 244 times

7

Hello I’m trying to reach the following url structure for the post personalizado portifolio:

  • website.com/portifolio - Display all posts - OK
  • website.com/portifolio/Slug - Displays the portifolio item with Slug slug - OK
  • website.com/portifolio/tags - List all posts related tags - does not work
  • website.com/portifolio/tags/Slug - Displays all posts tagged with Slug slug - OK

The tag here is a custom taxonomy, custom taxonomy created for the portifolio

Someone has done this successfully and can give me some example?

My code is like this:

register_taxonomy(
    'portfolio_tags',  
    'portfolio',       //post type name
    array(
        'labels' => array(
            'name' => 'Tags'
        ),
        'hierarchical'    => false,
        'rewrite'           => array( 
            'slug' => 'portfolio/tags'
         ),
    )
);
register_post_type( 'portfolio',
    array(
      'labels' => $labels,
      'public' => true,
      'has_archive' => true,
      'menu_icon' => 'dashicons-portfolio',
      'menu_position' => 5,
      'rewrite'     => array(
          'slug'      => 'portfolio', 
          'with_front'  => false
      )
    )
);
  • You created a template for this custom taxonomy ?

  • yes, to display the call arquivo of taxonomy this ok, I just wanted a page that was the index, where lists all categories.

1 answer

1

Alan, I’ll try to understand what you need.
You have the post type portfolios, and the taxonomy created by you called "tags"? You want to display the terms created in your taxonomy?
For example, let’s say your taxonomy is "types", your post-type is portfolios. The terms of taxonomy types could be: rectangular, square and round. Thus you would have portfolios of 3 different types. To list edsses 3 terms, one of the ways is to create a template with the following code:

$args = array( 'hide_empty=0' );

$terms = get_terms( 'portfolio_tags', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    $count = count( $terms );
    $i = 0;
    $term_list = '<p class="my_term-archive">';
    foreach ( $terms as $term ) {
        $i++;
        $term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) ) . '">' . $term->name . '</a>';
        if ( $count != $i ) {
            $term_list .= ' &middot; ';
        }
        else {
            $term_list .= '</p>';
        }
    }
    echo $term_list;
}

See if it fits you, anything just talk.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.