【问题标题】:Wordpress: Error 404 with pagination in custom taxonomy in homeWordpress:错误 404 在家中自定义分类中的分页
【发布时间】:2015-08-26 09:37:56
【问题描述】:

我在使用自定义分类的查询中遇到了分页问题。当我转到第二页时,这会返回一个 404 错误页面。

这是我的代码(在 index.php 中运行):

<?php
            $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
            $args = array(
                'post_type' => 'product',
                'posts_per_page' => 8,
                'tax_query' => array(
                    array(
                        'taxonomy'  => 'product_cat',
                        'field'     => 'slug',
                        'terms'     => array( 'destacado' ),
                        'operator'  => 'NOT IN',
                    ),
                ),
                'paged' => $paged
                );
            $loop = new WP_Query( $args );
            if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); ?>
                <li class="normal">
                    <a class="imagen" href="<?php echo get_permalink( $loop->post->ID ) ?>">
                        <?php the_post_thumbnail('thumbnail'); ?>
                    </a>
                    <a class="nombre" href="<?php echo get_permalink( $loop->post->ID ) ?>">
                        <?php the_title(); ?>
                    </a>
                    <p class="marca"><?php $terms = get_the_terms( $loop->post->ID, 'marca' ); foreach($terms as $term) { echo $term->name; } ?></p>
                    <p class="precio"><?php echo $product->get_price_html(); ?></p>
                    <span class="agregar"><?php woocommerce_template_loop_add_to_cart(); ?></span>
                </li>
            <?php endwhile; ?>

    </ul>

        <?php post_navigation(); ?>

            <?php } else { echo __( 'No products found' ); }?>
            <?php wp_reset_postdata();?>

functions.php 中的 post_navigation() 代码为:

function post_navigation() {
    echo '<div class="navigation">';
    echo '  <div class="next-posts">'.get_next_posts_link('&laquo; Older Entries').'</div>';
    echo '  <div class="prev-posts">'.get_previous_posts_link('Newer Entries &raquo;').'</div>';
    echo '</div>';
}

谢谢!

【问题讨论】:

标签: php pagination wordpress


【解决方案1】:

试试这个

array(
         array(
             'taxonomy'  => 'product_cat',
             'field'     => 'slug',
             'terms'     => array( 'destacado' ),
             'relation'  => 'NOT IN'
             ),
    ),

【讨论】:

  • 好吧……这没有发生任何事情:/
猜你喜欢
  • 2015-06-07
  • 2014-09-23
  • 2017-09-22
  • 2014-04-17
  • 1970-01-01
  • 2020-03-22
  • 2012-01-06
  • 2021-07-25
  • 2021-08-19
相关资源
最近更新 更多