我的主题中有个文件名为single-audio.php
和single video.php
, 但当我点击音频帖子格式或视频帖子格式时,wordpress会使用index.php
而不是我的single-audio.php
或single-video.php
文件。有什么想法吗?
POST格式“音频”和“视频”仅在index.php中显示
3 个回复
最合适的回答,由SO网友:Jared 整理而成
两者之间有着巨大的区别Post Formats 和Post Types. 我假设您使用的是post格式,它没有供您使用的默认模板文件。
但你能做的是使用has_post_format()
要查看帖子是否具有您使用的格式,如果有,请使用get_template_part()
获取您创建的要在其中显示的特定模板文件。
例如:
// If this post has a post format of \'video\'
if( has_post_format( \'video\', $post->ID ) ) {
// Then get and display \'single-video.php\'
get_template_part( \'single\', \'video\' );
}
SO网友:ungestaltbar
如果您真的想为每种post格式类型使用单个文件,可以尝试以下操作:(粘贴到functions.php)
function post_format_template() {
global $post;
$format = get_post_format($post->ID);
if ( is_single() && $format ) {
include(\'single-format-\'.$format.\'.php\');
exit;
}
}
add_action(\'template_redirect\', \'post_format_template\',10);
这是一个可能的解决方案,但我不建议这样做,只要你不能百分之百确定自己正在做什么。这里发生了什么。Jared回应是处理帖子格式的推荐方式。
SO网友:rexposadas
如果我正确理解您的问题,您需要执行以下操作:
通过仪表板添加一个新页面,给新页面命名为“Audio post format”,并将该页面与模板关联。有一个选择框,允许您选择模板HTH
结束