Wordpress获取模板部分

时间:2015-03-28 14:18:11

标签: php wordpress templates

通过WordPress模板我找到了获取模板

<?php 
            if ( is_home() ) {
                get_template_part('home', 'featured'); 
                get_template_part('home', 'recent');
            }
        ?>

在显示主页时调用某些模板部件。

有没有办法对某些页面使用相同的功能?例如domain-name.com/contact

由于

1 个答案:

答案 0 :(得分:1)

您可以使用is_page来确定页面。例如:

if ( is_page('contact') ) {
    get_template_part('home', 'featured'); 
    get_template_part('home', 'recent');
}

该功能的参数可以是Page ID,Page Title或Page Slug。