【问题标题】:Get wordpress post in diffrent div but one by one逐一获取不同div中的wordpress帖子
【发布时间】:2012-08-15 17:27:15
【问题描述】:

我的 wordpress 博客中有 10 个帖子,我想要这样的内容: div class="something1" post1 post5 post9 /div

div class="something2" post2 post6 10 后 /div div class="something3" post3 post7 post4 post8 /div

我不知道,但我一定需要它,请帮忙。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    在您的循环中,您需要使用 php 增加您的 div。我没有对此进行测试,但这应该可以工作:

    <div class="yourClass">
    <?php
        $myCustomClass = 0;
        $args = array
        (
            'posts_per_page' => 4,
            'orderby'     => 'name',
            'order'       => 'DEC',
            'post_type'   => 'post',
            'post_status' => 'publish'
        );
        $loop = new WP_Query( $args );
    
        while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <?php $myCustomClass++ ?>
    
                <div class="myCustomClass-<?php echo $myCustomClass;?>">
    
                    <h2>
                        <a href="<?php the_permalink();?>">
                            <?php the_title(); ?>
                        </a>
                    </h2>
    
                    <div class="my-post-content">
    
                        <?php the_content(); ?>
    
                    </div>
    
                </div>
    <? endwhile; ?>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      相关资源
      最近更新 更多