【发布时间】:2015-07-28 09:27:00
【问题描述】:
我为具有两种自定义分类法“颜色”和“样式”的产品创建了自定义帖子类型。产品在这两个中都被标记。当您转到分类术语页面时,它会正常工作,即如果您转到 /colour/blue,它会列出所有蓝色产品。
我想要发生的是,当您转到 /colour/blue 时会列出所有蓝色产品,但按第二个分类“样式”对它们进行分组,显示前三个产品并带有阅读更多链接。
所以
蓝色>产品风格1
- 产品1
- 产品 2
- 产品 3
查看更多..
蓝色>产品风格2
- 产品 3
- 产品 4
- 产品 5
查看更多..
有谁知道这是否可行?
当前代码是这样的,我已经为术语 taxonomy-colour.php 创建了一个分类模板
<?php get_header(); ?>
<main role="main" class="blinds">
<h1 class="main-product-title">Products</h1>
<!-- section -->
<section class="main-product-content">
<h2><?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h2>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post image -->
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php the_post_thumbnail(array(720,400)); // Declare pixel size you need inside the array ?>
<?php endif; ?>
<!-- /post thumbnail -->
<!-- post title -->
<h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
<!-- /post title -->
<p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">View ></a></p>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
<?php get_template_part('pagination'); ?>
</section>
<!-- /section -->
<div class="sidebar-wrapper">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('product-sidebar')) ?>
</div>
</main>
【问题讨论】:
-
到目前为止你有什么代码?
-
您好,我已经为分类法创建了一个模板,即 taxonomy-colour.php 并将其放在上面。
-
我之前已经回答过类似的问题,无论是在这里还是在WordPress Development,只是不记得在哪里,但本质上,您需要使用
the_posts过滤器并使用usort()处理帖子 -
谢谢。我将查看 the_posts 过滤器,看看是否可以将其应用于我的问题。