【问题标题】:(Wordpress) Irregular 3-4-3-4 Post structure(Wordpress) 不规则的 3-4-3-4 帖子结构
【发布时间】:2016-07-29 17:44:14
【问题描述】:

如何将 wordpress 帖子对齐到这样的不规则结构中:


帖子 1 |发表 2 |发布 3

第 4 行 |发布 5 |帖子 6 |发布 7

发布 8 |发布 9 |发布 10

第 11 行 |发布 12 |发表 13 |发布 14


帖子显示为列表。我需要一些逻辑来将帖子对齐到不规则的结构中。

<?php get_header(); ?>

<!-- Getting posts -->
<div class="kategorie-vypis">
  <div class="container">
    <h1 class="stredny-nadpis">Kategorie</h1>
    <ul>
            <?php foreach((get_the_category()) as $category) { ?>
                <h3><?php echo $category->category_description . ' '; ?></h3>
                <?php $catVal = $category->cat_ID; }
            $IDOutsideLoop = $post->ID;
            global $post;
            $myposts = get_posts('category=1&showposts=999'.$catVal);
            foreach ($myposts as $post) { ?>
                <li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current-post jeden-vypis\""; } ?>>
                    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('small-thumbnail', array('class' => 'img-responsive logo-mini')); ?><span class="jeden-vypis-link"><?php the_title(); ?></span></a></li>
            <?php }; ?>
    </ul>
  </div>
</div>


<?php get_footer(); ?>

【问题讨论】:

    标签: php html css wordpress twitter-bootstrap


    【解决方案1】:

    只需使用几个变量:

    <?php 
    $control = 3;
    $current = 0;
    foreach((get_the_category()) as $category) { 
      if ($current == 0)
        echo "<div>";
    ?>
      /***************************************/
      <?php 
      $current++;
      if ($current >= $control){
        echo "</div>";
        $current == 0;
        if($control == 3)
          $control = 4;
        else
          $control == 3;
      }
     }; ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2018-08-03
      相关资源
      最近更新 更多