WP Query taxonomy.php以显示当前学期的帖子


WP Query taxonomy.php to display posts from current term

我在taxonomy.php文件中使用以下wp_query来尝试显示该分类法中某个术语中的帖子列表。

我还有6个分类法,我希望将其应用到其中,因此我希望使$args 'taxonomy' => 'topic''terms' => 'arabisation'成为动态的,以与用户正在查看的当前页面相关。

感谢

<?php get_header(); ?>
<?php get_sidebar(); ?>
<section id="hero-image">
    <div class="gradient-overlay">
        <?php 
        // vars
        $queried_object = get_queried_object(); 
        $taxonomy = $queried_object->taxonomy;
        $term_id = $queried_object->term_id;
        $image = get_field('image', $taxonomy . '_' . $term_id);
        // load image for this taxonomy term (term object)
        echo '<img src="'.$image['sizes']['large'].'" />';
        ?>
    </div>
    <div class="grid">
        <header class="unit full-width">
            <a href="<?php echo home_url(); ?>/" title="Kurdistan Memory Programme" class="logo"><?php bloginfo( 'name' ); ?></a>
        </header>
        <footer class="unit one-half">
            <h1><?php single_cat_title(); ?></h1>
            <h4 class="scroll-down">Scroll down to continue</h4>
        </footer>
    </div>
</section>
<main class="grid">  
<? if ( have_posts() ) : ?>
<? while ( have_posts() ) : the_post(); ?>
    <div class="unit col-6-12">
        <figure class="thumbnail">
            <? if ( has_post_thumbnail() ) { 
                  the_post_thumbnail();
            } ?>
            <figcaption>
                <h4><? the_title(); ?></h4>
                <h5><? the_excerpt(); ?></h5>
                <h6><a href="<? the_permalink(); ?>">View Project</a></h6>
            </figcaption>
        </figure>
    </div>
<? endwhile; ?>
<? endif; ?>   
</main>
<?php get_footer(); ?>

Taxonomy.php文件已经运行了一个查询,该查询返回应用了该分类术语的帖子,所以请尝试以下操作:

<?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <div class="unit col-6-12">
            <figure class="thumbnail">
                <?php if ( has_post_thumbnail() ) { 
                      the_post_thumbnail();
                } ?>
                <figcaption>
                    <h4><? the_title(); ?></h4>
                    <h5><? the_excerpt(); ?></h5>
                    <h6><a href="<? the_permalink(); ?>">View Project</a></h6>
                </figcaption>
            </figure>
        </div>
    <?php endwhile; ?>
<?php endif; ?>

taxonomy.php文件将自动填充循环,因此您只需要使用标准的wordpress循环来循环浏览与所选分类术语匹配的所有帖子。