douke9545 2016-06-13 09:07
浏览 30
已采纳

在不同的列中显示wordpress帖子

I try to figure out to display the wordpress posts in my blog page in different columns. Example : First two posts in two rows, remaining posts in two columns one by one same as attached.

How can i display posts same as attached?

Thanks in Advance!!

enter image description here

And here is my code.

<div class="container">
<div class="row">
    <div class="col-xs-12 col-sm-6">
                <?php
                $news_args = array(
                    'cat' => 3,
                    'paged' => get_query_var('paged'),
                    'posts_per_page' => 4,
                    'orderby' => 'post_date',
                    'order' => 'DESC',
                );
                $news_query = new WP_Query($news_args);
                if ($news_query->have_posts()) :
                while ($news_query->have_posts()) : $news_query->the_post();
                ?>

                                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                    <p><span><?php the_time('F j, Y'); ?>
                                    </span>
                                    <span><?php echo "By: ".get_the_author(); ?>
                                    </span>
                                    <span>
                                    <?php
                                    $commentcount = comments_number('0', '1', '%');
                                    $fulltitle = $title . ' (' . $commentcount . ' comments)';
                                    ?>Comments<?php wp_count_comments( $post_id ); ?> 
                                    </span></p>

                                <figure class="fig_rel1">
                                <?php the_post_thumbnail(); ?>
                                </figure>
                                <p>
                                <?php
                                $content = get_the_content('',FALSE,'');
                                $content = apply_filters('the_content', $content);
                                $content = str_replace(']]>', ']]>', $content);
                                echo substr($content,0,300).'<a href="'. get_permalink($post->ID) .'">Read More &raquo; </a>';
                                ?>
                                </p>

                <?php
                endwhile;
                previous_posts_link('prev', $news_query->max_num_pages);
                echo ' &mdash; ';
                next_posts_link('next', $news_query->max_num_pages);
                endif;
                ?>

                </div>
                </div>
                </div>
  • 写回答

3条回答 默认 最新

  • doulao3078 2016-06-13 09:42
    关注

    It can help you.

    $news_args = array(
        'cat' => 3,
        'paged' => get_query_var('paged'),
        'posts_per_page' => 4,
        'orderby' => 'post_date',
        'order' => 'DESC',
    );
    
    $news_query = new WP_Query($news_args);
    
    $count = 0;
    
    if ($news_query->have_posts()) :
    while ($news_query->have_posts()) : $news_query->the_post();
    
        if ( $count < 2 ) {
           //code to populate first two post
           $count++;
        }else
           //code to populate remaining posts
           $count++;
        }
    
    endwhile;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab