WordPress循环问题 [英] WordPress Loop Issue
本文介绍了WordPress循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组带有精选图片的Wordpress帖子。图像将以网格样式格式显示为3行。
单击图像时,该帖子的内容应显示在当前行的下方在下一行之上。
我写了一个自定义循环,但我的问题如下:
在特定行中,onclick内容不会显示为图像1或2,除非该行已满(3个帖子存在。)
我显示了我的页面模板代码如下。
I have a set of Wordpress posts with featured images. The images will be displayed in rows of 3 in a grid style format.
When an image is clicked on, the content for that post should be display below the current row and above the next row.
I have written a custom loop, however my problem is as follows:
In a specific row, the onclick content doesn't display for image 1 or 2 unless the row is full (3 posts present.)
I have displayed my page template code below.
<?php
/*
Template Name: Sponsors Grid
*/ ?>
<?php get_header(); ?>
<div id="content">
<div class="slide slide3 sponsors" data-slide="3" data-stellar-background-ratio="0.5">
<div class="wrap">
<div class="fourcol thanks">
<h2>The NML Awards would not be possible without our amazing sponsors</h2>
</div>
<div class="sevencol logos">
<?php
$counter = 1; //start counter
$grids = 3; //Grids per row
$wp_query = new WP_Query('showposts=30&&orderby=date&&order=asc&&cat=6');
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php if($counter == 1) : ?>
<div class="sponsor_logos">
<a id="sponsor<?php echo the_ID(); ?>"><div class="threecol sponsor"><?php the_post_thumbnail('bones-thumb-150'); ?></div></a>
</div>
<div class="content">
<?php $id1 = get_the_ID(); ?>
<?php $url1 = wp_get_attachment_url( get_post_thumbnail_id($id1, 'bones-thumb-150') ); ?>
<?php $title1 = get_the_title(); ?>
<?php ob_start(); the_content(); $content1 = ob_get_clean(); ?>
</div>
<?php elseif($counter == 2) : ?>
<?php $id2 = get_the_ID(); ?>
<div class="sponsor_logos">
<a id="sponsor<?php echo the_ID(); ?>"><div class="threecol sponsor"><?php the_post_thumbnail('bones-thumb-150'); ?></div></a>
</div>
<div class="content">
<?php $url2 = wp_get_attachment_url( get_post_thumbnail_id($id2, 'bones-thumb-150') ); ?>
<?php $title2 = get_the_title(); ?>
<?php ob_start(); the_content(); $content2 = ob_get_clean(); ?>
</div>
<?php elseif($counter == $grids) : ?>
<?php $id3 = get_the_ID(); ?>
<div class="sponsor_logos">
<a id="sponsor<?php echo the_ID(); ?>"><div class="threecol sponsor"><?php the_post_thumbnail('bones-thumb-150'); ?></div></a>
</div>
<div class="content">
<?php $url3 = wp_get_attachment_url( get_post_thumbnail_id($id3, 'bones-thumb-150') ); ?>
<?php $title3 = get_the_title(); ?>
<?php ob_start(); the_content(); $content3 = ob_get_clean(); ?>
</div>
<div class="clearfix"></div>
<div class="sponsor_info">
<div id="sponsor<?php echo $id1; ?>content" class="sponsor_content">
<img src="<?php echo $url1; ?>" />
<h2><?php echo $title1; ?></h2>
<?php echo $content1; ?>
</div>
</div>
<div class="sponsor_info">
<div id="sponsor<?php echo $id2; ?>content" class="sponsor_content">
<img src="<?php echo $url2; ?>" />
<h2><?php echo $title2; ?></h2>
<?php echo $content2; ?>
</div>
</div>
<div class="sponsor_info">
<div id="sponsor<?php echo $id3; ?>content" class="sponsor_content">
<img src="<?php echo $url3; ?>" />
<h2><?php echo $title3; ?></h2>
<?php echo $content3; ?>
</div>
</div>
<?php $counter = 0; endif; ?>
<?php $counter++; endwhile; ?>
<?php endif; ?>
</div> <!-- .sevencol -->
</div> <!-- .wrap -->
</div> <!-- .slide -->
</div> <!-- .content -->
<?php get_footer(); ?>
推荐答案
counter = 1; //开始计数器
counter = 1; //start counter
grids = 3; //每行网格
grids = 3; //Grids per row
wp_query = new WP_Query('showposts = 30&& orderby = date&& order = asc&& cat = 6');
if(
wp_query = new WP_Query('showposts=30&&orderby=date&&order=asc&&cat=6'); if (
这篇关于WordPress循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文