我使用的是WordPress 3.5.1/二十一二主题。我正在使用自定义字段并在类别中显示它们。php按照以下方式,php是在类别内设置的。“/*启动循环*/”中的php
$metastime = get_post_meta($post->ID,\'user_submit_starttime\',true);
echo \'<a class="metastime">\'.$metastime.\'</a>\';
$metaetime = get_post_meta($post->ID,\'user_submit_endtime\',true);
echo \'<a class="metaetime">\'.$metaetime.\'</a>\';
$metaloc = get_post_meta($post->ID,\'user_submit_location\',true);
echo \'<a class="metaloc">\'.$metaloc.\'</a>\';
它的工作原理与我查看类别存档时显示的自定义字段相同(自定义字段显示在每个帖子标题下),但我认为有更好的功能可以使用。像下面这样?
get_template_part( \'content\', get_post_format() );
因为代码是特定于内容的。php,我希望自定义字段显示
<div class="entry-content"> <?php the_content(\'Read more...\'); ?> </div>
驻留在内容中。php,显示自定义字段的最佳方式是什么,以便它们显示在类别中显示的“条目内容”。php?
最合适的回答,由SO网友:birgire 整理而成
你可以试试the_content
使用条件标记筛选is_category()
要在查看类别存档时将字符串附加到帖子内容,请执行以下操作:
add_filter( \'the_content\', \'custom_the_content\' );
function custom_the_content( $content ){
if( is_category() ):
$metastime = get_post_meta( get_the_ID(), \'user_submit_starttime\', true );
$metaetime = get_post_meta( get_the_ID(), \'user_submit_endtime\' , true );
$metaloc = get_post_meta( get_the_ID(), \'user_submit_location\' , true );
$content .= \'<a class="metastime">\' . $metastime . \'</a>\';
$content .= \'<a class="metaetime">\' . $metaetime . \'</a>\';
$content .= \'<a class="metaloc">\' . $metaloc . \'</a>\';
endif;
return $content;
}