【问题标题】:My wordpress page doesn't filter on tags and categories我的 wordpress 页面没有过滤标签和类别
【发布时间】:2015-04-19 18:30:57
【问题描述】:

我正在创建一个 wordpress 网站,将帖子显示为网格中的图像。我已经在网格之前显示了帖子的类别和标签,我希望根据所选标签或类别实现对缩略图的过滤。但是,它目前似乎不起作用。即使选择了标签或类别,也会显示所有帖子。

<div id="grid">
                    <div class="container">
                        <div class="row text-center">
                            <?php 
                            $thumbnails = get_posts( 'numberposts=500' );
                            foreach ( $thumbnails as $thumbnail ) {
                            if ( has_post_thumbnail( $thumbnail->ID ) ) {
                                echo '<div class="col-md-4 col-lg-4"><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
                                echo get_the_post_thumbnail( $thumbnail->ID, 'large' );
                                echo '</a></div>';
                            }
                            }
                            ?>
                        </div>
                    </div>
                </div>

我怀疑它与“numberposts”有关,但即使我更改它,帖子仍然没有被过滤。

你知道是什么原因造成的吗?

【问题讨论】:

  • 提供的代码中没有进行过滤。

标签: php wordpress image twitter-bootstrap thumbnails


【解决方案1】:

如果您想要一个过滤列表,那么您需要过滤查询结果。

如果您将代码更改为:

$thumbnails = get_posts( array(
    'numberposts' => 500,
    ...
) );

然后您可以根据您未显示的设置添加过滤参数,例如

'tag' => $tag_slug or 'tag_id' => $tag_id
'cat' => $cat_id or 'category_name' => $catSlug

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-12
    • 2015-06-27
    • 1970-01-01
    • 2011-08-23
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2013-01-11
    相关资源
    最近更新 更多