0

I created a custom taxonomy "people". I select the related person in each post. In single.php file I can get the related person of a post. I can also get the list of all posts of a person through a link like www.mysite.com/people/john/

What I need now is a page that lists all "people". Is there an already implemented file for it?

1

There is not a file for this.

get_terms( $taxonomies, $args )

So you will need to create your own template then select it from the list of templates in a page in.

  • how can I reach this page if I create a new template file? – mustafa Dec 15 '14 at 6:39
  • If you created the template correctly you should be able to select it from the list of templates in a page. – David Dec 15 '14 at 7:02
  • You should add your comment through an edit to your answer. – Pieter Goosen Dec 15 '14 at 7:14
  • 1
    Thank you. I updated it. Will be sure to do this in the future. – David Dec 15 '14 at 7:18
0

For a recent project, I had to do this.

Here is the code I used to gather the custom post type categories:

$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
}

Assuming John is a tag, the variable $term_link will grab that link so you can put it into your code.

I also had custom post type tags and this is the code that I used to retrieve those:

echo '<div class="states">';
  $argsState = array(
    'smallest'                  => 16,
    'largest'                   => 16,
    'unit'                      => 'px',
    'number'                    => 50,
    'format'                    => 'flat',
    'separator'                 => "&#183;",
    '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 '<h4 class="widget-title">Peruse by State</h4>';
wp_tag_cloud( $argsState );
echo '</div>';

You would, of course, have to modify this code to agree with your custom post type's tags and categories.

Here's all the code for that template:

<?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 '<div class="cities">';
    $argsCity = array(
        'smallest'                  => 16,
        'largest'                   => 16,
        'unit'                      => 'px',
        'number'                    => 50,
        'format'                    => 'flat',
        'separator'                 => "&#183;",
        '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 '<h4 class="widget-title">Peruse by City</h4>';
    wp_tag_cloud( $argsCity );
    echo '</div>';
    echo '<div class="states">';
    $argsState = array(
        'smallest'                  => 16,
        'largest'                   => 16,
        'unit'                      => 'px',
        'number'                    => 50,
        'format'                    => 'flat',
        'separator'                 => "&#183;",
        '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 '<h4 class="widget-title">Peruse by State</h4>';
    wp_tag_cloud( $argsState );
    echo '</div>';
    echo '<p>&nbsp;</p>';
    echo '<div class="story-content" itemscope="itemscope" itemtype="http://schema.org/ItemList">';
    $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 '<h2 itemprop="name"><a href="' . $term_link .'">' . $term->name . '</a><span class="entry-meta"> (' . $count . ' ' . $label . ')</span></h2>';
    echo '<meta itemprop="itemListOrder" content="Unordered" />';
    if ( $count == 0 ) {
        echo '<p>No stories found.</p>';
        echo '<p class="postlist-entry-meta">Be the first to <a href="' . $blogurl . '/add-your-story/">add your <b>' . $term->name . '</b> story</a>!</p>';
    }
    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 = '<a href="' . $cityLinkConstruct . '">' . $postCityName . '</a>';
        $postStateTerms = wp_get_post_terms($postID, 'state', array("fields" => "all"));
        $postState = $postStateTerms[0]->slug;
        $postStateName = $postStateTerms[0]->name;
        $stateLinkConstruct = $blogurl . '/states/' . $postState;
        $postStateLink = '<a href="' . $stateLinkConstruct . '">' . $postStateName . '</a>';
        echo '<ul class="ckicon">';
        echo '<hr>';
        echo '<li itemprop="itemListElement">';
        echo '<span itemprop="url"><a href="' . get_post_permalink($postID) .'" rel="bookmark" title="' . get_the_title($postID) . '">' . get_the_title($postID) .'</a></span><br>';
        echo '<span class="entry-meta">Dateline: <span itemprop="datePublished"> ' . $postDate . '</span> <span class="middot-large">&middot</span> ' . $postCityLink . ', ' . $postStateLink . '</span>';
        //echo '<hr>';
        echo ( wpautop (the_excerpt()) );
        echo '</li>';
        echo '</ul>';
        endwhile;
        if ( $count <> 0 ) {
            echo '<p class="postlist-entry-meta">View all Stories in&nbsp;<a href="' . $term_link .'">' . $term->name . '</a>.&nbsp;&nbsp;<a href="' . $blogurl . '/add-your-story/">Share your <b>' . $term->name . '</b> story</a>!'; }
    wp_reset_postdata();
    }
    echo '</div><!-- end itemscope -->';
}

genesis();

I should caution that, on a site with a lot of posts, the above template could process slowly on the wrong hosting service.

Hope this helps.

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.