我正在尝试创建一个图库类型的页面,其中显示每个帖子类别中的一个帖子缩略图。问题是,我想在一个九方形网格的中间显示页面标题和指向公文包页面的链接。我在想最好的方法是在三列中显示四个缩略图,然后显示页面标题,然后再显示四个缩略图。我有前四个这样的:
Updated code:
<?php
$count = 0;
$taxonomy = \'category\';// e.g. post_tag, category
$param_type = \'category__in\'; // e.g. tag__in, category__in
$term_args=array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) { ?>
<ul class="row portfolio-entries">
<?php
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 1,
\'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
$post_count = $my_query->post_count;
if( $my_query->have_posts() ) :
$count++;
if ($count <= 4) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li class="span4 box portfolio-entry">
<div class="hover-state align-right">
<h2><?php the_category(); ?></h2>
<h3><?php the_title(); ?></h3>
<em>Click for details</em>
</div><!-- end hover-state -->
<?php if (has_post_thumbnail()) : ?>
<figure><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></figure>
<?php endif; ?>
</li>
<?php
endwhile;
}
endif;
} /* end foreach term*/
?>
<li class="span4 portfolio-entry">
<header class="align-center">
<h1>Galleries</h1>
<div class="cta align-center">
<a href="<?php echo home_url(); ?>/portfolio" class="btn btn-primary">See Full Portfolio</a>
</div><!-- end cta -->
</header>
</li>
<?php
if ($count >= 4) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li class="span4 box portfolio-entry">
<div class="hover-state align-right">
<h2><?php the_category(); ?></h2>
<h3><?php the_title(); ?></h3>
<em>Click for details</em>
</div><!-- end hover-state -->
<?php if (has_post_thumbnail()) : ?>
<figure><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></figure>
<?php endif; ?>
</li>
<?php endwhile;
} ?>
</ul> <?php
} /* end if terms */
wp_reset_query(); // Restore global post data stomped by the_post().
?>
我的问题是第二个循环。我已经得到了if声明if ($count > $more_cats_to_show && $count <= $max_count)
但我似乎无法获得接下来的4个缩略图。