Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 重置计数的Wp\U查询_Wordpress_Gridview_Masonry - Fatal编程技术网

Wordpress 重置计数的Wp\U查询

Wordpress 重置计数的Wp\U查询,wordpress,gridview,masonry,Wordpress,Gridview,Masonry,我想在分类页面中使用wp_查询循环,并使用下面的代码,但它得到了一个错误:该站点遇到了技术难题。那么如何改进我的代码呢?谢谢你的帮助! [![在此处输入图像描述][1][1] <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <?php if($counter == 1) : ?> <div class="col-<?php echo counter; ?>"> //t

我想在分类页面中使用wp_查询循环,并使用下面的代码,但它得到了一个错误:该站点遇到了技术难题。那么如何改进我的代码呢?谢谢你的帮助! [![在此处输入图像描述][1][1]

<?php if(have_posts()) :  while(have_posts()) :  the_post(); 
?>
<?php
if($counter == 1) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 300px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 150px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>
<div class="clear"></div>
<?php
elseif($counter == 3) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 150px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>          
<?php endif; ?>


  [1]: https://i.stack.imgur.com/jgolS.png

我认为代码很好,但需要稍微修改一下。 您只需要一个砌体库,否则它很难用多个div包装器和语句保持所需的形式

设置之后,您需要在css中为类1-5定义所需的高度

.col-1,.col-2,.col-3,.col-4,.col-5 {width:50%;}
.col-1,.col-2 {height:300;}
.col-3,.col-4,.col-5{height:150px;}
砌体库为您完成对齐工作

<?php 
$counter = 1;
if(have_posts()) :  while(have_posts()) :  the_post(); 
if($counter == 1) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 300px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 150px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>
<div class="clear"></div>
<?php
elseif($counter == 3) :
?>
<div class="col-<?php echo counter; ?>"> //this col have width 50%, height 150px.
  <div class="postimage">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('project-thumb'); ?></a>
  </div>
  <div class="proj-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</div>          
<?php endif; 
$counter++;
if( $counter == 5 ): $counter = 1; endif;
endwhile; endif;
?>

你会遇到什么错误,你想要什么样的结果?这是html css模板:,我想要回显number来计算类col-{number}。我把这段代码放在我的分类模板中,希望所有的帖子循环都能正常工作,谢谢,但它只显示5个帖子,所以如何循环行?我有5列,想从6列的职位将申请第1列,第2列7。。。等