2nd post different layout

时间:2014-05-14 作者:rwzdoorn

作为一名设计师,我是一个为帖子做不同布局以使页面更加不同的***孔。因此,我尝试创建以下内容:

enter image description here

这是我目前正在尝试修复的代码。

[编辑]我已经把样式做好了,但现在内容被复制了

<?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>  &nbsp;&#47;&nbsp;  \';
                                    }}


            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>  &nbsp;&#47;&nbsp;  \';
                                    }}


            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。。

1 个回复
最合适的回答,由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;

?>

结束

相关推荐

Pre_Get_Posts税查询不适用于自定义作者页面

我正在使用主题Twenty12,并修改了文件作者中的标准post查询。php,代码如下:function wpd_author_query( $query ) { //CODE to set $current_user_name here //This gets the author from the URL $author = get_user_by(\'slug\',get_query_var(\'author_name\')); $current_user_name