【问题标题】:Wordpress category posts filter by tagWordpress 类别帖子按标签过滤
【发布时间】:2020-07-20 21:00:03
【问题描述】:

我有一个 wordpress 网站,我想在其中创建一个页面,其中列出了特定类别的帖子。在此页面中应该有一个标签过滤器,用于按此类别的标签过滤帖子。就像按属性过滤的投资组合图像一样。我需要帮助来编写过滤器的代码。谢谢!

【问题讨论】:

  • 您必须自定义程序。仅使用 Divi 构建器是无法做到这一点的。
  • 只需访问类别存档页面并添加 get-param:post_tag=slug-of-tag 应该可以开箱即用。例如:someplace.tld/?cat=vegetables&post_tag=nightshade/category/vegetables?post_tag=leafy-greens,无论您的 url-schema 是什么
  • 嘿 Norbert,为了确保我理解您的问题,您想显示来自特定类别的帖子吗?多个类别?尽量准确。在您的主题上,“作品集图像”是自定义帖子类型吗?没有详细信息,我们无能为力。程序员不是巫师。

标签: wordpress


【解决方案1】:

@amarinediary 我已经制作了一个自定义页面模板,其中列出了“商店”类别中的帖子:

<?php
$args = array(
    'category' => 101,
    'post_type' =>  'post',
    'orderby' => 'title',
    'order' => 'ASC', 
    'posts_per_page' => '-1000',
);

$postslist = get_posts( $args );?>  

<div class="entry-content shops">
                        
    <?php foreach ($postslist as $post) :  setup_postdata($post); ?>
                        
        <div class="col-4">
                                  
            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="<?php the_title_attribute(); ?>">

                <div class="shop-info">

                    <h5><?php the_title(); ?></h5>

                    <?php the_excerpt(); ?>

                    <span class="go">go to the shop <i class="fa fa-angle-right"></i></span>

                </div>
                                    
<?php the_post_thumbnail('name of your thumbnail'); ?>

              </a>

        </div>
                              
    <?php  endforeach;?>
    
</div> <!-- .entry-content -->


我想按标签对这些帖子进行分类,例如“面包店、银行、咖啡店、时尚等”。我想在页面顶部放置一个过滤器,过滤器必须只包含那些已经从“商店”类别中订购帖子的标签。

【讨论】:

    【解决方案2】:

    你可以这样使用

    $query= new WP_Query(array(
                'post_type'         => array('Your-Post-Type'),
                'posts_per_page'    => -1,
                'post_status'       => 'publish',
                'orderby'           => 'DESC',
                'category' => 101,
                'tax_query'  => array(
                    array(
                        'taxonomy'  => 'post_tag',
                        'field'     => 'slug',
                        'terms'     =>  array(
                            'slug1',
                            'slug2',
                        ),
                    ),
                ),
                ));
    

    【讨论】:

      猜你喜欢
      • 2019-02-15
      • 2014-12-12
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多