Php 使用is_home()为不同的页面选择不同的页面模板
我正在开发一个Wordpress 3.9.1网站,主题为214。 通常,该主题允许我从它为每个页面提供的3个不同模板中进行选择,它们是默认的-全宽-贡献者页面 对于主页,我使用的是全宽模板,它还调用另一个名为content page.php的模板部分 我创建了另一个名为content pagehome.php的文件,复制了content page.php中的所有内容,并在其中添加了一些类似这样的内容Php 使用is_home()为不同的页面选择不同的页面模板,php,html,wordpress,Php,Html,Wordpress,我正在开发一个Wordpress 3.9.1网站,主题为214。 通常,该主题允许我从它为每个页面提供的3个不同模板中进行选择,它们是默认的-全宽-贡献者页面 对于主页,我使用的是全宽模板,它还调用另一个名为content page.php的模板部分 我创建了另一个名为content pagehome.php的文件,复制了content page.php中的所有内容,并在其中添加了一些类似这样的内容 <article id="post-<?php the_ID(); ?>" &
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> class="homepage-content-styles">
<?php
// Page thumbnail and title.
twentyfourteen_post_thumbnail();
the_title( '<header class="entry-header"><h1 class="entry-title">', '</h1></header><!-- .entry-header -->' );
?>
<div class="entry-content">
<?php
the_content();
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
edit_post_link( __( 'Edit', 'twentyfourteen' ), '<span class="edit-link">', '</span>' );
?>
</div><!-- .entry-content -->
<!-- This is the part I've added -->
<div style="margin-top:7%;">
<h5 style="margin-left:5%;"><a title="Buscas hotel en Costa Rica?" href="http://veranta.com/country/costa-rica-hotels/buscas-hotel-en-costa-rica/">Hoteles en Costa Rica</a></h5>
<h5 style="margin-left:5%;"><a title="Buscas hotel en Panama?" href="http://veranta.com/country/ofertas-y-hoteles-en-panama/buscas-hotel-en-panama/">Hoteles en Panama</a></h5>
<h5 style="margin-left:5%;"><a title="Buscas hotel en Nicaragua?" href="http://veranta.com/country/book-nicaragua-hotels/buscas-hotel-en-nicaragua/">Hoteles en Nicaragua</a></h5>
<h3 style="text-align: center; margin-left:4%; margin-top:10%;"><strong>Veranta trabaja con los mejores proveedores de reservaciones de la región <br class="none" /> y directamente con hoteles, B&B, y condominios para conseguir <br class="none" /> la mejor oferta de hoteles de Centroamérica.<br class="none" /> Compare cientos de precios en solo lugar<br class="none" /> y ahorre en sus reservaciones de hotel.</strong></h3></div>
</article><!-- #post-## -->
Veranta trabaja con los mejores proveedores de reservacions de la región
y酒店、B&;B、 y中央美洲酒店管理委员会公寓。
比较单独卢加酒店管理委员会公寓。
酒店管理委员会公寓。
然后在full width.php中,我将调用content-page.php的语句更改为if-else语句
get_header(); ?>
<div id="main-content" class="main-content">
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
//if it is home get template part content-page-home.php else get content-page.php
if ( is_home() ) {
// Include the page content template.
get_template_part( 'content', 'pagehome' );
} else {
get_template_part( 'content', 'page' );
}
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile;
?>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_sidebar();
get_footer();
get_header();?>
发现问题后,仍想保留此问题作为他人参考
有两个不同的布尔函数,它们是is_home()
和is_front_page()
is\u front\u page()
在我的例子中是正确的选项,因为我有一个静态页面显示在首页上,在函数引用中它说:
当显示主博客页面且设置->阅读->首页显示设置为“您的最新文章”
,或设置为“静态页面”,且“首页”值为当前显示的页面时,返回TRUE
如果我有一个博客文章索引(“自定义”中的“您最新的文章”选项)
我需要使用参考资料中所述的is_home()
:
is_home()
检查博客帖子索引页是否显示为首页
我仍然无法结束这个问题,因为我无法在两天内接受我的答案。如果你认为这必须关闭,请投赞成票
谢谢。可能的副本