显示自定义分类的所有术语

时间:2014-12-14 作者:mustafa

我创建了一个自定义分类法“人”。我在每个岗位上选择相关人员。单件。php文件我可以得到相关人员的一个帖子。我还可以通过www.mysite这样的链接获得一个人所有帖子的列表。com/人/约翰/

我现在需要的是一个列出所有“人”的页面。是否有已实现的文件?

2 个回复
SO网友:David

没有此文件。

get_terms( $taxonomies, $args )

所以你需要create your own template 然后select it 从中的页面中的模板列表中。

SO网友:Marj Wyatt

对于最近的一个项目,我必须这样做。

以下是我用来收集自定义帖子类型类别的代码:

$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
}
假设John是一个标记,变量$term\\u link将获取该链接,以便您可以将其放入代码中。

我还有自定义的post类型标记,这是我用来检索这些标记的代码:

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>\';
当然,您必须修改此代码以符合自定义帖子类型的标记和类别。

以下是该模板的所有代码:

<?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();
我应该提醒大家,在一个有很多帖子的网站上,上面的模板可能在错误的托管服务上处理得很慢。

希望这有帮助。

结束

相关推荐

Random taxonomy category list

我正在尝试在页面上显示一个自定义分类列表。我想显示五个,但当页面刷新时,它们以不同的随机顺序排列。我尝试过使用shuffle,但它只对前5个进行shuffle,其他的都看不到。我试过了orderby RAND 但它不起作用。这是我目前的代码。<?php $all_artists = get_terms( \'artists\', array( \"number\" => 5, \'hide_empty\' =>