我几个星期以来一直在关注这个问题,经常遇到同样的问题。这是一个复杂的设置:
我有一个名为“档案”的类别。我还有一个自定义分类“档案”,用于分组关于同一个新闻事件或故事的帖子。 当有人创建帖子时,他们可以将帖子分配给某个档案,然后将其放入“档案”类别中。这样,所有档案帖都归入同一类别,同时仍然有办法将故事彼此分开。
我需要“档案”类别的类别页面来显示分类标准“档案”中的所有自定义分类术语。反过来,这些链接到他们自己的特定档案列表。我创建了category-dossiers.php文件,它取代了默认的类别页面,所以这不再是问题了。
使用其他论坛帖子,特别是这个帖子,我已经解决了大部分问题。类别页面显示所有分类术语,包含链接和所有内容,并可将它们分成页面。 (这有点hacky,因为WordPress通常不使用术语作为主要内容块,但是帖子)。
我现在唯一的问题是让第二页,第三页等工作。在第一页之外,它只显示我主题的默认index.php文件。
这是完整的模板页面。任何人都可以弄清楚它有什么问题吗?我尝试过但尝试过但似乎无法找到问题。
<?php get_header(); ?>
<?php get_sidebar (); ?>
<section class="articles grid main-content category">
<header class="grid-header">
<h2><?php single_cat_title();?></h2>
</header>
<?php
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var('paged');
}
else if ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
}
else {
$paged = 1;
}
$per_page = 20;
$number_of_terms = count( get_terms( "dossiers") );
$offset = $per_page * ( $paged - 1) ;
// Setup the arguments to pass in
$args = array(
'order' => 'ASC',
'orderby' => 'menu_order',
'offset' => $offset,
'number' => $per_page
);
// Gather the terms
$terms = get_terms("dossiers", $args);
$count = count($terms);
if ( $count > 0 ){
echo "<ul>";
foreach ( $terms as $term ) {?>
<li class="article">
<a href="<?php echo get_term_link( $term ); ?>">
<?
if ( get_field('banner', $term->taxonomy._.$term->term_id) ) { // check if the post has a Banner Image assigned to it.
$image = get_field('banner', $term->taxonomy._.$term->term_id);
echo '<img class="wp-post-image" src="'.$image[sizes]['thumbnail'].'" />';
}
else {
echo '<img class="wp-post-image" src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/missing-thumbnail.png" />';
}
?>
<div class="meta-info" />
<div class="caption" data-category="<?php $category = get_the_category(); echo $category[0]->slug; ?>"><?php echo $term->name; ?> </div>
</div>
</a>
</li>
<?}
echo "</ul>";
}
?>
</section>
<nav class="pagination">
<?php
if($terms) {
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '/page/%#%',
'current' => $paged,
'total' => ceil( $number_of_terms / $per_page ), // 3 items per page
'type' => 'list',
'mid_size' => 5
) );
}
?>
</nav>
<?php get_footer(); ?>
答案 0 :(得分:0)
更改查询数组
$ args = array( 'order'=&gt; 'ASC', 'orderby'=&gt; 'menu_order', 'offset'=&gt; $抵消, 'paged'=&gt; $ per_page );
而不是使用分页的数字。