嘗試按自定義分類術語和默認文章按類別分頁自定義文章類型,但它不起作用。我是WordPress的新手,我做了大量的谷歌搜索,沒有找到解決我的問題的詳細解決方案。WordPress分頁不能處理自定義文章類型和分類術語
如果有人知道請分享您的答案,這真的很感激。
注:我創建了一個自定義主題。
這裏是我的分類法product_category.php頁面代碼:
<?php get_header();?>
<div class="container-fluid pages">
<div class="container" style="margin-top: 10%;">
<div class="row">
<div class="col-sm-8">
<div class="panel panel-default">
<?php $term = get_queried_object();
$taxonomy = get_taxonomy($term->taxonomy);
?>
<div class="panel-heading"><h4><?php echo 'محصولات : '.$term- >name;?></h4></div>
<div class="panel-body">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type'=>'my_product',
'taxonomy'=>$taxonomy->name,
'posts_per_page'=> 1,
'term'=>$term->slug,
'paged'=>$paged);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()): $query->the_post(); ?>
<div class="thumbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail('featured');
} ?>
<div class="caption caption-content">
<h3 class="product-name"><?php the_title(); ?></h3>
<p class="text-muted">
<!-- <strong>نویسنده:</strong> <?php //the_author();?> -->
تاریخ: <?php the_date(); ?> </p>
<p> <?php the_excerpt(); ?> </p>
<div>
<p class="price-box">
<i class="fa fa- circle"> </i>قیمت:
<?php if (the_field('price') == '') {
// echo "00.00";
} else {
the_field('price');
} ?>
</p>
</div>
</div>
<hr>
</div>
<?php endwhile;
}
else {
echo '<h3>هیچ موردی درین بخش یافت نشد.</h3>';
}
?>
<!-- pagination here -->
<p>
<nav>
<?php if (function_exists('custom_pagination' )) {
custom_pagination($custom_query- >max_num_pages,"", $paged);
} ?>
</nav>
<?php wp_reset_postdata(); ?>
</p>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer();?>
當我點擊下頁它重定向我的索引頁面,網址仍然是: http://localhost/goldsotre/product_category/ring/page/2/ Custom_pagination功能:
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
您可以嘗試刪除空間,也請粘貼您的自定義分頁功能 $ custom_query-> max_num_pages到$ custom_query-> max_num_pages –