作为一名设计师,我是一个为帖子做不同布局以使页面更加不同的***孔。因此,我尝试创建以下内容:
这是我目前正在尝试修复的代码。
[编辑]我已经把样式做好了,但现在内容被复制了
<?php
$query = new WP_Query( array( \'post_type\' => array( \'innovation_lab\' ) ) );
while ( $query->have_posts() ) : $query->the_post();
$i=0;
if ($i%3==0) echo \'
<div class="row border">
\';
echo \'
<div class="col-lg-6">
<a href="\'; the_permalink(); echo \'">\';
echo \'<h1>\'; the_title(); echo \'</h1></a><p>\';
foreach((get_the_category()) as $childcat) {
if (cat_is_ancestor_of(10, $childcat)) {
echo \'<a href="\'.get_category_link($childcat->cat_ID).\'" class="category small">\';
echo $childcat->cat_name . \'</a> / \';
}}
echo \'</p><p>\';
echo excerpt(60);
echo \'</p>\';
echo \'\';
echo \'<p><a href="\'; the_permalink(); echo \'" class="btn btn btn-readmore" >Lees meer</a></p>
</div>
<div class="col-lg-6">
<p class="pull-right">\';
the_post_thumbnail(\'\', array(\'class\' => \'pull-right img-responsive img-samenvatting\'));
echo \'</p></div></div>\';
if ($i%3==2) echo \'
\';
echo \'
<div class="row border"><div class="col-lg-6">\';
the_post_thumbnail(\'\', array(\'class\' => \'pull-right img-responsive img-samenvatting\'));
echo \'</div>
<div class="col-lg-6">
<a href="\'; the_permalink(); echo \'">\';
echo \'<h1>\'; the_title(); echo \'</h1></a><p>\';
foreach((get_the_category()) as $childcat) {
if (cat_is_ancestor_of(10, $childcat)) {
echo \'<a href="\'.get_category_link($childcat->cat_ID).\'" class="category small">\';
echo $childcat->cat_name . \'</a> / \';
}}
echo \'</p><p>\';
echo excerpt(60);
echo \'</p>\';
echo \'\';
echo \'<p><a href="\'; the_permalink(); echo \'" class="btn btn btn-readmore" >Lees meer</a></p>
</div></div>\';
if ($i%3==3) echo \'</div>\';
$i++;
endwhile;
?>
PS:请不要评判我的PHP。。
最合适的回答,由SO网友:rwzdoorn 整理而成
找到Ok解决方案。我忘了使用{},现在它工作了。下面是:
<?php
$query = new WP_Query( array( \'post_type\' => array( \'custom_post_type\' ) ) );
$i = 0;
while ( $query->have_posts() ) : $query->the_post();
if ($i%2==0){
echo \'1st post here\';
}
if ($i%2==1){
echo \'2nd post here\';
}
$i++;
endwhile;
?>