Custom post url structure with tags and tag listing

7

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

  • website.com/portifolio - Displays all posts - OK
  • website.com/portifolio/slug - Displays the portlet item with slug slug - OK
  • website.com/portifolio/tags - List all tags related to post type - 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 portifolio

Has anyone done this successfully and can you give me some examples?

My code looks 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
      )
    )
);
    
asked by anonymous 17.11.2015 / 19:22

1 answer

1

Alan, I'll try to understand what you need. Do you have the post type portfolios, and the taxonomy created by you called "tags"? Do you want to display the terms created in this taxonomy?
For example, let's say that your taxonomy is "types", your post-type is portfolios. The terms of the taxonomy types could be: rectangular, square and round. So 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's up to you, just talk.

    
17.07.2016 / 19:53