自定义发布类型档案和不显示自定义分类数据的单个页面

时间:2013-05-07 作者:electricbrickco

我有一个名为“Newsitems”的自定义帖子类型,我为其注册了两个自定义分类:“newsitem types”和“news item tags”

我希望这两个分类法的术语看起来像是类别和标签的典型post meta信息,但在客户端的请求下,它们需要比默认post meta单独工作。

尽管花了将近15个小时的时间,我仍然无法让它们渲染。

备注:

在单个贴子页面上,我确实获得了“newsitem type”ID号,但无法输出实际的税务术语名称存档页的我的代码:

function custom_do_loop() {

// Intro Text (from page content)
echo \'<div class="page hentry entry">\';
echo \'<h1 class="entry-title">\'. get_the_title() .\'</h1>\';
echo \'<div class="entry-content">\' . get_the_content() ;

$args = array(
    \'post_type\' => \'newsitem\', // enter your custom post type
    \'orderby\' => \'date\',
    \'order\' => \'DESC\',
    \'posts_per_page\'=> \'12\',  // overrides posts per page in theme settings
    \'paged\' => get_query_var( \'paged\' ),
);

$terms = get_the_terms( $post->ID , \'newsitem-type\' );

$loop = new WP_Query( $args );
if( $loop->have_posts() ):

    while( $loop->have_posts() ): $loop->the_post(); global $post;

    echo \'<div class="newsitem-listing wrap">\';
        echo \'<h3><a href="\' . genesis_get_custom_field( \'_cmb_newsitem_url\' ) . \'" title="\'. get_the_title() . \'">\' . get_the_title() . \'</a></h3>\';
        echo \'<div class="newsitem-subtitle">\' . genesis_get_custom_field( \'_cmb_newsitem_subtitle\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-source">\' . genesis_get_custom_field( \'_cmb_newsitem_source\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-type">\' . $terms->name . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-author">\' . genesis_get_custom_field( \'_cmb_newsitem_author\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-pubdate">\' . genesis_get_custom_field( \'_cmb_newsitem_pub_date\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="synopsis">\' . get_the_content() . \'</div>\';   
    echo \'</div>\';

    endwhile; 

    genesis_posts_nav();    

endif;

wp_reset_query();

// Outro Text (hard coded)
echo \'</div><!-- end .entry-content -->\';
echo \'</div><!-- end .page .hentry .entry -->\';
}

我的单篇文章代码:

add_action(\'genesis_before_post_content\', \'envision_newsitem_meta\');
 function envision_newsitem_meta() {
 global $wp_query;

 $postid = $wp_query->post->ID;
 $subtitle = get_post_meta($postid, \'_cmb_newsitem_subtitle\' , true);
 $source = get_post_meta($postid, \'_cmb_newsitem_source\' , true);
 $cattypes = get_post_meta($postid, \'_cmb_newsitem_cat_type\' , true);
 $author = get_post_meta($postid, \'_cmb_newsitem_author\' , true);
 $date = get_post_meta($postid, \'_cmb_newsitem_pub_date\' , true);
 $url = get_post_meta($postid, \'_cmb_newsitem_url\' , true);
 $tag = get_post_meta($posid, \'post_tag\' , true);

 $cattypeString = implode (\',\' , $cattypes);

 echo \'<div class="newsitem-meta"><strong>Subtitle:</strong> \' . $subtitle . \'</div>\' .       \'<div class="newsitem-meta"><strong>Source:</strong> \' . $source . \'</div>\' . \'<div   class="newsitem-meta"><strong>Author:</strong> \' . $author . \'</div>\' . \'<div class="newsitem-meta"><strong>Article Type:</strong> \' . $cattypeString . \'</div>\' . \'<div class="newsitem-meta"><strong>Date Published:</strong> \' . $date . \'</div>\' . \'<div class="newsitem-meta"><strong>URL:</strong> <a href="\' . $url . \'" target="_blank">\' . $url . \'</a></div>\';

 wp_reset_query();
 }

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

get_the_terms() 您正在使用的是返回项的数组,不能简单地回显到页面。

您应该尝试使用更高级别get_the_term_list() 函数,该函数返回串联结果的字符串,并可以进行回显。

结束

相关推荐

使用$TERMS的分层视图的分类下拉列表

我在Wordpress论坛上问过这个问题,但现在没有得到任何回复,我希望我可以在这里问。我找到密码了here 我的代码是:function exc_custom_taxonomy_dropdown( $taxonomy, $orderby, $order, $hierarchical, $show_count, $name) { $args = array( \'orderby\' => \'name\', \'order\' =&g

自定义发布类型档案和不显示自定义分类数据的单个页面 - 小码农CODE - 行之有效找到问题解决它

自定义发布类型档案和不显示自定义分类数据的单个页面

时间:2013-05-07 作者:electricbrickco

我有一个名为“Newsitems”的自定义帖子类型,我为其注册了两个自定义分类:“newsitem types”和“news item tags”

我希望这两个分类法的术语看起来像是类别和标签的典型post meta信息,但在客户端的请求下,它们需要比默认post meta单独工作。

尽管花了将近15个小时的时间,我仍然无法让它们渲染。

备注:

在单个贴子页面上,我确实获得了“newsitem type”ID号,但无法输出实际的税务术语名称存档页的我的代码:

function custom_do_loop() {

// Intro Text (from page content)
echo \'<div class="page hentry entry">\';
echo \'<h1 class="entry-title">\'. get_the_title() .\'</h1>\';
echo \'<div class="entry-content">\' . get_the_content() ;

$args = array(
    \'post_type\' => \'newsitem\', // enter your custom post type
    \'orderby\' => \'date\',
    \'order\' => \'DESC\',
    \'posts_per_page\'=> \'12\',  // overrides posts per page in theme settings
    \'paged\' => get_query_var( \'paged\' ),
);

$terms = get_the_terms( $post->ID , \'newsitem-type\' );

$loop = new WP_Query( $args );
if( $loop->have_posts() ):

    while( $loop->have_posts() ): $loop->the_post(); global $post;

    echo \'<div class="newsitem-listing wrap">\';
        echo \'<h3><a href="\' . genesis_get_custom_field( \'_cmb_newsitem_url\' ) . \'" title="\'. get_the_title() . \'">\' . get_the_title() . \'</a></h3>\';
        echo \'<div class="newsitem-subtitle">\' . genesis_get_custom_field( \'_cmb_newsitem_subtitle\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-source">\' . genesis_get_custom_field( \'_cmb_newsitem_source\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-type">\' . $terms->name . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-author">\' . genesis_get_custom_field( \'_cmb_newsitem_author\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="newsitem-pubdate">\' . genesis_get_custom_field( \'_cmb_newsitem_pub_date\' ) . \'</div>\'; //retrieve custom field
        echo \'<div class="synopsis">\' . get_the_content() . \'</div>\';   
    echo \'</div>\';

    endwhile; 

    genesis_posts_nav();    

endif;

wp_reset_query();

// Outro Text (hard coded)
echo \'</div><!-- end .entry-content -->\';
echo \'</div><!-- end .page .hentry .entry -->\';
}

我的单篇文章代码:

add_action(\'genesis_before_post_content\', \'envision_newsitem_meta\');
 function envision_newsitem_meta() {
 global $wp_query;

 $postid = $wp_query->post->ID;
 $subtitle = get_post_meta($postid, \'_cmb_newsitem_subtitle\' , true);
 $source = get_post_meta($postid, \'_cmb_newsitem_source\' , true);
 $cattypes = get_post_meta($postid, \'_cmb_newsitem_cat_type\' , true);
 $author = get_post_meta($postid, \'_cmb_newsitem_author\' , true);
 $date = get_post_meta($postid, \'_cmb_newsitem_pub_date\' , true);
 $url = get_post_meta($postid, \'_cmb_newsitem_url\' , true);
 $tag = get_post_meta($posid, \'post_tag\' , true);

 $cattypeString = implode (\',\' , $cattypes);

 echo \'<div class="newsitem-meta"><strong>Subtitle:</strong> \' . $subtitle . \'</div>\' .       \'<div class="newsitem-meta"><strong>Source:</strong> \' . $source . \'</div>\' . \'<div   class="newsitem-meta"><strong>Author:</strong> \' . $author . \'</div>\' . \'<div class="newsitem-meta"><strong>Article Type:</strong> \' . $cattypeString . \'</div>\' . \'<div class="newsitem-meta"><strong>Date Published:</strong> \' . $date . \'</div>\' . \'<div class="newsitem-meta"><strong>URL:</strong> <a href="\' . $url . \'" target="_blank">\' . $url . \'</a></div>\';

 wp_reset_query();
 }

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

get_the_terms() 您正在使用的是返回项的数组,不能简单地回显到页面。

您应该尝试使用更高级别get_the_term_list() 函数,该函数返回串联结果的字符串,并可以进行回显。