我正在尝试为包含来自特定分类的所有帖子的页面创建创世纪分页。我会使用这个 WordPress Stack Exchange 中给出的许多解决方案,但我不知道如何将他们wp_query
的 's 与我的结合起来。我该怎么做呢?(请记住,我绝不是专业人士。)
在我尝试集成分页之前,这是我模板中的内容:
remove_action('genesis_loop','genesis_do_loop');
add_action('genesis_loop','get_article_content');
function get_article_content(){
$myterms = get_terms('article-category', 'orderby=none&hide_empty');
foreach ($myterms as $term) :
$args = array(
'post_type' => 'solar-articles',
'tax_query' => array(
array(
$term->slug
)
),
);
// assigning variables to the loop
global $wp_query;
$wp_query = new WP_Query($args);
endforeach;
// starting loop
while ($wp_query->have_posts()) : $wp_query->the_post();
?><div class="col-md-12"><?php
the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' );
?><p class="entry-time">POSTED <?php the_time('F j, Y'); ?></p>
<div class="entry-content"><?php
the_excerpt();
?></div></div><?php
endwhile;
}
genesis();
这是我尝试集成后的结果:
remove_action('genesis_loop','genesis_do_loop');
add_action('genesis_loop','get_article_content');
function get_article_content(){
$paged = 1;
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
if ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
$paged = intval( $paged );
$myterms = get_terms('article-category', 'orderby=none&hide_empty');
foreach ($myterms as $term) :
$args = array(
'posts_per_page' => 3,
'post_type' => 'solar-articles',
'tax_query' => array(
array(
$term->slug
)
),
'paged' => $paged
);
// assigning variables to the loop
global $wp_query;
$wp_query = new WP_Query($args);
endforeach;
// starting loop
while ($wp_query->have_posts()) : $wp_query->the_post();
?><div class="col-md-12"><?php
the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' );
?><p class="entry-time">POSTED <?php the_time('F j, Y'); ?></p>
<div class="entry-content"><?php
the_excerpt();
?></div></div><?php
endwhile;
genesis_posts_nav();
}
genesis();