首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在wordpress WP_Query中将左侧位置和顶部位置放置在post循环中

在wordpress WP_Query中将左侧位置和顶部位置放置在post循环中
EN

Stack Overflow用户
提问于 2013-07-28 02:25:14
回答 1查看 138关注 0票数 0

我已经完成了三栏的布置从一个教程。这是很棒的。但我想要一个样式表包括在"div“中。现在我就这样出去了

代码语言:javascript
复制
<div class="post-col1" id="post-125">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>
</div>

我用过的代码是

代码语言:javascript
复制
<?php if (have_posts ()):?>
<?php $col = 1;
while($loop->have_posts()): $loop->the_post();?>
<?php if ($col == 1)?>
<div class = "post-col<?php echo $col; ?>" id = "post-<?php the_ID();?>" style=" top: 0; left: 305; ">
  <h4 class="member-name"> <a href = "<?php the_permalink(); ?>" title = "<?php the_title(); ?>"><?php the_title();?> </a> </h4>
  <h4 class="phone-number"><?php echo get_post_meta($post->ID, 'members_phone-one',true) ?></h4>


  </div>
  <?php
  if($col == 1) {$col = 2;} else {
  if($col != 1) {
  if($col == 3) {$col = 1;}
  if($col == 2) {$col = 3;}
  }
  }
  endwhile; ?>  
</div>

现在,我想在这个循环中包含一个样式表。所以我的输出应该会喜欢这个。

代码语言:javascript
复制
<div class="post-col1" id="post-125" style="
    top: 0;
    left: 0;
">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>

      </div>
<div class="post-col2" id="post-125" style="
    top: 0;
    left: 300;
">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>

      </div>
<div class="post-col3" id="post-125" style="
    top: 0;
    left: 600;
">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>

      </div>
<div class="post-col1" id="post-125" style="
    top: 300;
    left: 0;
">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>

      </div>
<div class="post-col1" id="post-125" style="
    top: 300;
    left: 600;
">
      <h4 class="member-name"> <a href="/TantraProjects/Ranjit/mdmar/members/tshgueuj/" title="Tshgueuj">Tshgueuj </a> </h4>
      <h4 class="phone-number">34543</h4>

      </div>

希望这是可以理解的。如果是的话,请帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-28 10:38:04

由于已经分配了一个post-colN类,所以可以在样式表中分配left属性,而不是在HTML中编写它们:

代码语言:javascript
复制
.post-col1 { left: 0; }
.post-col2 { left: 300px; }
.post-col3 { left: 600px; }

然后,这样的东西应该可以工作(我还没有测试过,但希望您可以纠正任何类型的输入):

代码语言:javascript
复制
<?php if (have_posts ()):
    $col = 1;
    $top = 0;
    while($loop->have_posts()):
        $loop->the_post(); ?>
        <div class="post-col<?php echo $col; ?>" id="post-<?php the_ID();?>" style="top: <?php echo $top; ?>px;">
            <h4 class="member-name"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
            <h4 class="phone-number"><?php echo get_post_meta($post->ID, 'members_phone-one',true) ?></h4>
        </div>
        <?php
        $col++;
        if ($col > 3) {
            $col = 1;
            $top += 300;
        }
    endwhile;
endif; ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17904410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档