标签页未列出所有带有标签的帖子

时间:2017-02-13 作者:Hope

我正在使用tag。php在用户访问标记页时显示内容。我需要的一切都很好,但它只显示了最近6篇有标签的帖子。我需要它列出所有贴子的标签。

当我把阅读下的“博客页面最多显示”改为大量时,它会破坏我网站的一部分,所以我想在标签中这样做。php代码。

我知道您可以使用“posts\\u per\\u page”=>-1参数列出所有帖子,但在我的代码中实现它时遇到了困难。

这是我的标签。php文件

<?php 

        if ( have_posts() ) : ?>

            <?php $term_id = get_queried_object_id(); ?>
            <div class="pantry-thumbnail"><?php the_term_thumbnail( $term_id, $size = \'post-thumbnail\', $attr = \'\' ) ?></div>


            <?php
                // Show an optional term description.
                $term_description = term_description();
                if ( ! empty( $term_description ) ) :
                    printf( \'<div class="taxonomy-description">%s</div>\', $term_description );
                endif;
            ?>

            <strong>Recipes</strong>


            <?php
                // Start the Loop.
                while ( have_posts() ) : the_post();

            ?>

            <ul>
                <li>
                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </li>
            </ul>


            <?
                endwhile;

                else :
                    // If no content, include the "No posts found" template.
                    get_template_part( \'content\', \'none\' );

                endif;

                wp_reset_query();
            ?>
谢谢你的帮助!

1 个回复
SO网友:Hope

我可以通过将其添加到函数中来解决此问题。php文件

function wpa69774_limit_tags( $query ) {
 if ( $query->is_tag() && $query->is_main_query() ) {
    $query->set( \'posts_per_page\', -1 );
 }
}
add_action( \'pre_get_posts\', \'wpa69774_limit_tags\' );
在最终跌跌撞撞地问了这个问题之后:Can't Get 'tag' Page To Display only Tagged Posts

相关推荐

Use Tags to initiate Search

首先,我是Wordpress和PHP的新手,如果这是一个基本问题,我深表歉意。我安装了Wordpress,每篇文章都用标签标记,这些标签包含以下链接:href=domain.com/index.php/tag/TAGNAME 但我希望链接是:href=domain.com/index.php/search/TAGNAME 据我所知,我需要改变get_tag_link() 但所做的就是使用get_term_link() 然后我完全迷路了。是否有一个函数If(tag){ return \"