single-aside.php,但我的帖子仍然使用single.php,但有格式。
嗨,我使用了post-formats(aside)作为我的一些帖子,尽管定义了新的post-type,但过去仍使用single.php对其进行样式设置,问题是我现在想使用不同于我的其他页面布局其他帖子和页面仅用于这种类型,但是当我创建single-aside.php时,wordpress不会使用此页面,并且我冲掉了我的永久链接,这不是问题。您认为单个页面是否可用于诸如aside,video,quote和...的默认帖子格式?有什么主意吗?
答案 0 :(得分:0)
根据文档,您可以使用has_post_format()
,在https://codex.wordpress.org/Post_Formats的“使用格式”下查看更多信息。
由于帖子格式不是自定义帖子类型,因此您需要将其添加到single.php
:
if ( has_post_format( 'aside' )) {
//Your custom code for aside goes here
}
或者,如果您想使用其他php文件,则可以创建自定义帖子类型并支持帖子格式。
注册支持:
add_action( 'init', 'aside_post_type' );
function aside_post_type() {
register_post_type( 'aside',
array(
'labels' => array( 'name' => __( 'Aside' ) ),
'public' => true,
'supports' => array('title', 'editor', 'post-formats') //this will give support for post formats
)
);
}
然后将single-aside.php
添加到主题中,并根据需要设置此自定义帖子类型的样式。