【问题标题】:Show Categorie(s) of a post in a list of custom posts在自定义帖子列表中显示帖子的类别
【发布时间】:2011-07-30 16:46:28
【问题描述】:

我已经搜索了很多这个问题,但我找到的只是关于如何显示特定分类的每个类别的答案。

我正在开发一个主题,我将使用 jQuery 过滤帖子列表(自定义帖子类型“工作”),但我需要一个 <div> 和一个显示特定类别的类发帖。

我将在类别页面(工作)上过滤这些。

为此,我将所有代码放入 loop.php。

<div class="post_entry">
        <div class="post-thumb"><?php the_post_thumbnail('single-post-thumbnail'); ?></div>
        <h4 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h4>
        <?php   
            $location = get_post_meta($post->ID, 'location', TRUE);
            $organization = get_post_meta($post->ID, 'organization', TRUE);
            $url = get_post_meta($post->ID, 'url', TRUE); 
        ?>
        <div class="post-meta">
            <?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
            <?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
            <?php if($url != ''){ ?><p class="post_meta_url">Website: <a href="<?php echo $url; ?>">Click Here</a></p><?php } ?>
        </div>
        <div class="hidden tags">

        </div>


<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
        <p class="post_excerpt"><?php the_excerpt(); ?></p>
<?php else : ?>
        <div class="category_read_more"><?php the_content( __( 'Read More', 'twentyten' ) ); ?></div>
        <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
<?php endif; ?>
            <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>

    <?php comments_template( '', true ); ?>
    </div>

我很幸运地添加了元框信息,但我想在&lt;div class="hidden tags"&gt;&lt;/div&gt; 中显示帖子自定义类别(jobtype)

要查看网站,请查看http://www.cirkut.net/wp/libertyguide/jobs

如果有人可以提供帮助,那就太好了!如果需要更多信息,请告诉我。

【问题讨论】:

    标签: wordpress show categories posts


    【解决方案1】:

    在循环中:

    Category: <?php echo get_the_category_list(', '); ?>
    

    更新:

    Wordpress 写道:

    列出条款

    如果你想在你的主题中有一个自定义列表,那么你可以通过 分类名称到循环中的 the_terms() 函数中,如下所示:

    the_terms($post->ID, 'people', 'People: ', ', ', ' ' );

    这应该可以解决您的问题。

    http://codex.wordpress.org/Taxonomies#Listing_the_terms

    【讨论】:

    • 这不起作用。我正在使用自定义分类法。为了更清楚一点,我需要将类别显示在空格分隔的列表中(例如,“web-dev career full-time”而不是“web/dev, career, full-time”)
    • 我已经更新了答案。希望这就是你正在寻找的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2014-10-03
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    相关资源
    最近更新 更多