我试图在我的主页上做的是从6个类别中抽取最新的帖子,但是我需要为每个帖子增加可变的$计数器(+1),以便我可以正确地设置它们的样式。
我成功地按正确的顺序显示了每个类别的最新帖子,但这样做我无法让$counter正常工作。
任何帮助都将不胜感激-谢谢!
<?php get_header(); ?>
<div class="col1">
<?php
if (get_option(\'woo_show_carousel\') == \'true\' AND !is_paged()) { include (TEMPLATEPATH . "/includes/featured.php");}
?>
<?php
if (is_paged()) $is_paged = true;
if (get_option(\'woo_slider_exclude\') == "true") $shownslides = get_option(\'woo_shown_slides\');
if(empty($showslides) || get_option(\'woo_show_carousel\') == \'false\'){
$showslides = array();
}
$showvideo = get_option(\'woo_show_video\');
$vidtags = get_option(\'woo_video_tags\');
if(!empty($vidtags)) {
$vidtags_array = explode(\',\',$vidtags);
} else {
$vidtags_array = array();
}
global $wpdb;
foreach ($vidtags_array as $tag_name){
$tag_name = trim($tag_name);
$tagid = $wpdb->get_var("SELECT term_ID FROM $wpdb->terms WHERE name=\'$tag_name\'");
$tagids[] = $tagid;
}
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$taxonomy = \'category\';// e.g. post_tag, category
$param_type = \'category__in\'; // e.g. tag__in, category__in
$term_args=array(
\'include\' => \'3,4,5,6,11,14\',
\'orderby\' => \'ID\',
\'order\' => \'ASC\'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
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,
\'post__not_in\' => $shownslides,
\'tag__not_in\' => $tagids,
\'paged\'=> $paged
);
query_posts($args);
$home_content = get_option(\'woo_home_content\');
$home_boxes = get_option(\'woo_home_boxes\');
if (have_posts()) :
$full = FALSE;
$width = get_option(\'woo_full_thumb_width\');
$height = get_option(\'woo_full_thumb_height\');
if( $home_boxes == \'On\') { $small = TRUE; }
elseif ($home_boxes == \'Off\') { $full = TRUE; }
else { $large_posts = intval($home_boxes); }
$counter = 0;
while (have_posts()) : the_post();
$counter++;
$post_class = \'full\';
if( ($counter > $large_posts OR $small == TRUE) AND $full == FALSE)
{
$width = get_option(\'woo_boxed_thumb_width\');
$height = get_option(\'woo_boxed_thumb_height\');
if( $small == FALSE ) $counter = 1;
$small = true;
if ($counter%2 == 0 ) { $post_class = \'fr\'; }
else { $post_class = \'fl\'; }
}
?>
<div class="post-outer post <?php echo $post_class; ?>">
<div class="post-inner post-alt">
<?php woo_get_image(\'image\',$width,$height); ?>
<h2><a title="<?php _e(\'Permalink to \',woothemes); ?><?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="category-head cufon"><?php the_category(\', \') ?></p>
<?php if ($home_content == \'false\') { ?>
<p><?php echo strip_tags(get_the_excerpt(), \'<a><strong>\'); ?></p>
<?php } else { ?>
<?php the_content(__(\'Continue Reading\',woothemes)); ?>
<?php } ?>
</div><!--/post-inner-->
</div><!--/post-->
<?php if ($counter%2 == 0 AND $small == TRUE ) { echo \'<div style="clear:both;"></div>\'; } ?>
<?php endwhile; ?>
<?php endif;
}
}
wp_reset_query();
?>
<div class="more_entries">
<?php if (function_exists(\'wp_pagenavi\')) wp_pagenavi(); else { ?>
<div class="fl"><?php previous_posts_link(__(\'« Newer Entries \',woothemes)) ?></div>
<div class="fr"><?php next_posts_link(__(\' Older Entries »\',woothemes)) ?></div>
<br class="fix" />
<?php } ?>
</div>
<div class="fix"></div>
<?php
if (get_option(\'woo_show_video\') == \'true\') { include (TEMPLATEPATH . "/includes/video.php");}
?>
<?php
if (get_option(\'woo_show_talking_points\') == \'true\') { include (TEMPLATEPATH . "/includes/talking-points.php");}
?>
</div><!--/col1-->
SO网友:Tim
好吧,经过一段时间的搜索,我似乎有这个工作,我希望这有助于某人。
<div class="col1">
<?php
if (get_option(\'woo_show_carousel\') == \'true\' AND !is_paged()) { include (TEMPLATEPATH . "/includes/featured.php");}
?>
<?php
if (is_paged()) $is_paged = true;
if (get_option(\'woo_slider_exclude\') == "true") $shownslides = get_option(\'woo_shown_slides\');
if(empty($showslides) || get_option(\'woo_show_carousel\') == \'false\'){
$showslides = array();
}
$showvideo = get_option(\'woo_show_video\');
$vidtags = get_option(\'woo_video_tags\');
if(!empty($vidtags)) {
$vidtags_array = explode(\',\',$vidtags);
} else {
$vidtags_array = array();
}
global $wpdb;
foreach ($vidtags_array as $tag_name){
$tag_name = trim($tag_name);
$tagid = $wpdb->get_var("SELECT term_ID FROM $wpdb->terms WHERE name=\'$tag_name\'");
$tagids[] = $tagid;
}
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$taxonomy = \'category\';// e.g. post_tag, category
$param_type = \'category__in\'; // e.g. tag__in, category__in
$term_args=array(
\'include\' => \'3,4,5,6,11,14\',
\'orderby\' => \'ID\',
\'order\' => \'ASC\'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
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,
\'post__not_in\' => $shownslides,
\'tag__not_in\' => $tagids,
\'paged\'=> $paged
);
query_posts($args);
$home_content = get_option(\'woo_home_content\');
$home_boxes = get_option(\'woo_home_boxes\');
static $counter = 0;
if (have_posts()) :
$full = FALSE;
$width = get_option(\'woo_full_thumb_width\');
$height = get_option(\'woo_full_thumb_height\');
if( $home_boxes == \'On\') { $small = TRUE; }
elseif ($home_boxes == \'Off\') { $full = TRUE; }
else { $large_posts = intval($home_boxes); }
while (have_posts()) : the_post();
$counter++;
$post_class = \'full\';
if( ($counter > $large_posts OR $small == TRUE) AND $full == FALSE)
{
$width = get_option(\'woo_boxed_thumb_width\');
$height = get_option(\'woo_boxed_thumb_height\');
if( $small == FALSE ) $counter = 1;
$small = true;
if ($counter%2 == 0 ) { $post_class = \'fr\'; }
else { $post_class = \'fl\'; }
}
?>
<div class="post-outer post <?php echo $post_class; ?>">
<div class="post-inner post-alt">
<?php woo_get_image(\'image\',$width,$height); ?>
<h2><a title="<?php _e(\'Permalink to \',woothemes); ?><?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="category-head cufon"><?php the_category(\', \') ?></p>
<?php if ($home_content == \'false\') { ?>
<p><?php echo strip_tags(get_the_excerpt(), \'<a><strong>\'); ?></p>
<?php } else { ?>
<?php the_content(__(\'Continue Reading\',woothemes)); ?>
<?php } ?>
</div><!--/post-inner-->
</div><!--/post-->
<?php if ($counter%2 == 0 AND $small == TRUE ) { echo \'<div style="clear:both;"></div>\'; } ?>
<?php endwhile; ?>
<?php endif;
}
}
wp_reset_query();
?>
<div class="more_entries">
<?php if (function_exists(\'wp_pagenavi\')) wp_pagenavi(); else { ?>
<div class="fl"><?php previous_posts_link(__(\'« Newer Entries \',woothemes)) ?></div>
<div class="fr"><?php next_posts_link(__(\' Older Entries »\',woothemes)) ?></div>
<br class="fix" />
<?php } ?>
</div>
<div class="fix"></div>
<?php
if (get_option(\'woo_show_video\') == \'true\') { include (TEMPLATEPATH . "/includes/video.php");}
?>
<?php
if (get_option(\'woo_show_talking_points\') == \'true\') { include (TEMPLATEPATH . "/includes/talking-points.php");}
?>
</div><!--/col1-->