我有一个名为“Newsitems”的自定义帖子类型,我为其注册了两个自定义分类:“newsitem types”和“news item tags”
我希望这两个分类法的术语看起来像是类别和标签的典型post meta信息,但在客户端的请求下,它们需要比默认post meta单独工作。
尽管花了将近15个小时的时间,我仍然无法让它们渲染。
备注:
在单个贴子页面上,我确实获得了“newsitem type”ID号,但无法输出实际的税务术语名称我意识到您将看到一些与Genesis相关的代码,因为我正在使用Genesis并使用Genesis自定义元框模板来构建它。然而,我的问题(我希望)与Genesis的功能和WordPress的常规行为关系不大。我觉得Genesis支持论坛没有这种情况我不是一个书呆子,但很明显,我对WordPress循环的理解还不够透彻存档页的我的代码:
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();
}