Für ein neues Projekt musste ich das tun.
Hier ist der Code, den ich verwendet habe, um die Kategorien für benutzerdefinierte Beitragstypen zu sammeln:
$profession_terms = get_terms( 'professions', array( 'orderby' => 'count', 'order' => 'DESC', 'hide_empty' => 0 ) ); foreach( $profession_terms as $term ) { $term_link = get_term_link( $term ); ... do other stuff }
Unter der Annahme, dass John ein Tag ist, wird die Variable $ term_link diesen Link aufnehmen, damit Sie ihn in Ihren Code einfügen können.
Ich hatte auch benutzerdefinierte Post-Typ-Tags und das ist der Code, den ich verwendet habe, um diese abzurufen:
echo ''; $argsState = array( 'smallest' => 16, 'largest' => 16, 'unit' => 'px', 'number' => 50, 'format' => 'flat', 'separator' => "·", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => null, 'include' => null, 'topic_count_text_callback' => default_topic_count_text, 'link' => 'view', 'taxonomy' => 'state', 'echo' => true, 'child_of' => null, // see Note! ); echo ''; wp_tag_cloud( $argsState ); echo '
';
Sie müssten diesen Code natürlich ändern, damit er mit den Tags und Kategorien Ihres benutzerdefinierten Beitragstyps übereinstimmt.
Hier ist der Code für diese Vorlage:
< ?php /* Template Name: Stories List * Description: Displays Professions with list of stories and link to custom taxonomy archive * Author: Marj Wyatt aka Virtually Marj * * Schema http://schema.org/ItemList */ if ( !is_user_logged_in() ) { wp_redirect( home_url('/oops-this-content-is-members-only') ); exit; } remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop add_action( 'genesis_loop', 'vm_stories_archive' ); // Add custom loop function vm_stories_archive() { echo ''; $argsCity = array( 'smallest' => 16, 'largest' => 16, 'unit' => 'px', 'number' => 50, 'format' => 'flat', 'separator' => "·", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => null, 'include' => null, 'topic_count_text_callback' => default_topic_count_text, 'link' => 'view', 'taxonomy' => 'city', 'echo' => true, 'child_of' => null, // see Note! ); echo '
'; wp_tag_cloud( $argsCity ); echo ''; echo '
'; $argsState = array( 'smallest' => 16, 'largest' => 16, 'unit' => 'px', 'number' => 50, 'format' => 'flat', 'separator' => "·", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => null, 'include' => null, 'topic_count_text_callback' => default_topic_count_text, 'link' => 'view', 'taxonomy' => 'state', 'echo' => true, 'child_of' => null, // see Note! ); echo ''; wp_tag_cloud( $argsState ); echo '
'; echo '
'; echo '
'; $profession_terms = get_terms( 'professions', array( 'orderby' => 'count', 'order' => 'DESC', 'hide_empty' => 0 ) ); foreach( $profession_terms as $term ) { $count = $term->count; $term_link = get_term_link( $term ); $blogurl = get_bloginfo('url'); // Define the query $args1 = array( 'posts_per_page' => -1, 'post_type' => 'shows', 'professions' => $term->slug ); $myQuery = new WP_Query( $args1 ); if ( $count == 1 ) { $label = 'Story'; } if ( ( $count > 1 ) || ( $count == 0 ) ) { $label = 'Stories'; } echo '
'; echo '
'; if ( $count == 0 ) { echo '
No stories found.
'; echo '
Be the first to add your ' . $term->name . ' story!
'; } while ( $myQuery->have_posts() ) : $myQuery->the_post(); $postID = get_the_ID(); $postDate = get_the_date('', $post->ID); $postTerms = wp_get_post_terms($postID, 'city', array("fields" => "all")); $postCity = $postTerms[0]->slug; $postCityName = $postTerms[0]->name; $cityLinkConstruct = $blogurl . '/cities/' . $postCity; $postCityLink = '
' . $postCityName . ''; $postStateTerms = wp_get_post_terms($postID, 'state', array("fields" => "all")); $postState = $postStateTerms[0]->slug; $postStateName = $postStateTerms[0]->name; $stateLinkConstruct = $blogurl . '/states/' . $postState; $postStateLink = '
' . $postStateName . ''; echo '
'; echo '
'; echo '- '; echo '' . get_the_title($postID) .'
'; echo 'Dateline: ' . $postDate . ' · ' . $postCityLink . ', ' . $postStateLink . ''; //echo '
'; echo ( wpautop (the_excerpt()) ); echo ' '; echo '
'; endwhile; if ( $count <> 0 ) { echo '
View all Stories in ' . $term->name . '. Share your ' . $term->name . ' story!'; } wp_reset_postdata(); } echo '
'; } genesis();
Ich sollte warnen, dass auf einer Website mit vielen Posts die obige Vorlage langsam auf dem falschen Hosting-Dienst verarbeitet werden konnte.
Hoffe das hilft.