以下是我需要对“归档”页面上的5列执行的操作:
我已经可以在一个循环中遍历类别和帖子,以很好地显示它们,我只是不知道如何将其拆分为列。我还需要分页。基本上每页只显示18篇文章的标题/摘录。有什么帮助吗?我的循环如下:
UPDATE: I am posted the working solution below. This works perfectly to break a continuous loop of posts sorted and displayed by category of any type or taxonomy.
WHAT STILL NEEDS WORK: 我似乎不知道如何使寻呼工作。我需要分页来计算总帖子数(忽略类别),并且每页仅显示12个左右。我添加了分页代码,但它被注释掉了。
<?php
// for a given post type, return all
$post_type = \'retailers\';
$tax = \'states\';
$tax_terms = get_terms($tax);
$post_counter = 0; // reset so we can generate columns
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
if ($tax_terms) { ?>
<ul class="column_wrap" style="margin:0 10px; padding:0; width:165px; float:left;">
<?php foreach ($tax_terms as $tax_term) {
$args=array(
\'post_type\' => $post_type,
"$tax" => $tax_term->slug,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
//\'posts_per_page\' => 15,
//\'paged\' => $paged,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'caller_get_posts\'=> 1
); // END $args
$my_query = null; // clear the query variable
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<li class="column_row" style="float:left;">
<div class="retailer_state_wrap" style="width:165px; float:left;">
<h4><?php echo $tax_term->name; ?></h4>
</div>
</li>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li class="column_row" style="float:left;">
<div class="retailer_wrap retailer_id-<?php the_ID(); ?>" style="padding:0; width:165px; float:left;">
<p>
<span class="retailer_title"><?php the_title(); ?></span><br />
<span class="retailer_address">
<?php if (get_post_meta($post->ID, \'_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0\', true)) { ?>
<?php echo get_post_meta($post->ID, \'_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0\', true); ?>
<?php } ?>
<?php echo " "; ?>
<?php if (get_post_meta($post->ID, \'_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0\', true)) { ?>
<?php echo get_post_meta($post->ID, \'_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0\', true); ?>
<?php } ?>
</span><br />
<span class="retailer_phone">
<?php if (get_post_meta($post->ID, \'_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0\', true)) {
echo get_post_meta($post->ID, \'_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0\', true); ?>
<?php } ?>
</span>
</p>
</div>
<?php $post_counter++; ?>
</li>
<?php if ( 0 == $post_counter % 7 ) { ?>
</ul>
<ul class="column_wrap" style="margin:0 10px; padding:0; width:165px; float:left;">
<?php } ?>
<?php
endwhile;
//wp_pagenavi( array( \'query\' => $my_query ) );
} // END if have_posts loop
wp_reset_query();
} // END foreach $tax_terms
} // END if $tax_terms
?>