在下面的代码中,我检查如果我在我的网站主页上,那么我将以2的偏移量向右移动列,对于所有其他页面,我不应该有任何偏移量。我正在尝试实现这个,但是我得到了一个错误。如果你能给我个提示,那就太好了。谢谢!
<?php if (is_front_page() ) {
echo '<div class="col-md-8 la-content-inside col-md-offset-2">';
while ( have_posts() ) { the_post(); }
} else {
echo '<div class="col-md-8 la-content-inside">';
while ( have_posts() ) { the_post(); }
}
?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>发布于 2016-02-11 10:18:59
在您的代码中,您正在if & else块中打开endwhile块&在条件块之后关闭endwhile。
试着使用
<?php
if (is_front_page() ) {
echo '<div class="col-md-8 la-content-inside col-md-offset-2">';
while (have_posts()) : the_post();
get_template_part( 'content', 'page' );
endwhile; // end of the loop.
}else {
echo '<div class="col-md-8 la-content-inside">';
while (have_posts()) : the_post();
get_template_part( 'content', 'page' );
endwhile; // end of the loop.
}
?>发布于 2016-02-11 10:17:56
让我们从清理您的代码开始。我在几行代码中编写代码,所以对于提问的人来说,这是可以理解的。(是的,你可以写得更有效率)
<?php
echo '<div class="col-md-8 la-content-inside';
// frontpage exception
if(is_front_page()) {
echo ' col-md-offset-2';
}
echo '>';
while(have_posts()) {
the_post();
get_template_part( 'content', 'page' );
}
echo '</div>';
?>如果这会产生错误。请将错误复制粘贴为此答复中的注释。
发布于 2016-02-11 10:55:26
试试下面的短代码..。威尔给你..。
<div class="col-md-8 la-content-inside <?php echo (is_home() ? 'col-md-offset-2' : '' );?> ">
<?php while (have_posts()) : the_post();
get_template_part( 'content', 'page' );
endwhile; // end of the loop.
?>
</div>您需要使用is_home()函数..。头版。
https://stackoverflow.com/questions/35335747
复制相似问题