在乔姆拉!文章可以使用多个模板。我只能把ath放在url的末尾?template=templatename,文章使用模板“templatename”。
这在Wordpress中可能吗?
在乔姆拉!文章可以使用多个模板。我只能把ath放在url的末尾?template=templatename,文章使用模板“templatename”。
这在Wordpress中可能吗?
是的,是的。但默认情况下不会。
但是你自己做很容易。
您可以通过两种方式完成:
single.php
模板文件只需添加if
声明和使用get_template_part
函数加载所选模板。所以你的单身。php文件可能如下所示:
<?php
if ( isset($_GET[\'template\']) ) {
switch ($_GET[\'template\']) {
case \'a\':
get_template_part(\'single-post-template-a\');
break;
...
}
} else {
get_template_part(\'single-post-template-default\');
}
single_template
挂钩function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == \'post\' && isset($_GET[\'template\']) ) {
switch ( $_GET[\'template\'] ) {
case \'a\':
return locate_template( array(\'/single-post-template-a.php\') );
break;
...
}
}
return $single_template;
}
add_filter( \'single_template\', \'get_custom_post_type_template\' );
/* Mini-Features */ ?> <div id=\"sub-featured\" class=\"<?php echo $main_css_class; ?> section\"> <h2 class=\"section-title\"><?php echo stripslashes( $featured_title ); ?></h2>