Wordpress is_page_template查询

时间:2014-10-13 11:55:29

标签: wordpress

我在wordpress网站上使用了一个插件,该插件使用查询来显示搜索结果,这就是查询的代码:

if ( $query->have_posts() )
{
?>
<?php echo $query->found_posts; ?> Ergebnisse gefunden<br />
<?php
while ($query->have_posts())
{
    $query->the_post();

    ?>
    <div>
        <?php  if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small");   echo '</p>'; } ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    </div>


    <?php
}
?>
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
<a href="#" class="pagi-prev">Previous</a> | <a href="#" class="pagi-next">Next</a>
<?php
}
else
{
echo "No Results Found";
}

搜索应该只显示使用特定页面模板的页面的结果(mytemplate.php)

我找到了解释此问题的文档http://codex.wordpress.org/Function_Reference/is_page_template,但我没有在上述查询中使用它。

任何帮助都会很好:) thx

1 个答案:

答案 0 :(得分:0)

请按以下方式进行。

if ( is_page_template( '{enter the name of page template with extension}' ) ) {
    // Enter your if code here 
} else {
    // Enter your else code here.
}

要使此代码生效,您必须在WordPress管理界面中创建页面时选择页面模板选项。

相关问题