在下划线中,我可以通过预获取帖子和常规博客帖子来获取自定义帖子类型。但是,不会显示发布日期和作者。如何修改模板标记(themeslug\\u posted\\u on)以显示它们?
我的预获取帖子过滤器:
add_filter( \'pre_get_posts\', \'get_my_cpt\' );
function get_my_cpt( $query ) {
if ( is_archive() || is_search() || is_home() && $query->is_main_query() )
$query->set( \'post_type\', array( \'post\', \'my_cpt\' ) );
return $query;
}
我要修改的下划线:
if ( ! function_exists( \'_s_posted_on\' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function _s_posted_on() {
$time_string = \'%2$s\';
if ( get_the_time( \'U\' ) !== get_the_modified_time( \'U\' ) ) {
$time_string = \'%2$s%4$s\';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( \'c\' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( \'c\' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
_x( \'Posted on %s\', \'post date\', \'_s\' ),
\'\' . $time_string . \'\'
);
$byline = sprintf(
_x( \'by %s\', \'post author\', \'_s\' ),
\'\' . esc_html( get_the_author() ) . \'\'
);
echo \'\' . $posted_on . \' \' . $byline . \'\';
}
endif;
Answer:我找错地方了。答案在于“内容”。php的下划线文件。显示的预期结果是将我的cpt添加到条件中,如下所示:
if ( \'post\' || \'my_cpt\' == get_post_type() ) :