WP Query taxonomy.php 显示当前词条的帖子 [英] WP Query taxonomy.php to display posts from current term

查看:23
本文介绍了WP Query taxonomy.php 显示当前词条的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我也有 6 个分类法,我希望将其应用于,所以我想制作 $args 'taxonomy' =>'topic''terms' =>'arabisation' 动态,与用户正在查看的当前页面相关.

谢谢

<?php get_sidebar();?><section id="英雄形象"><div class="gradient-overlay"><?php//变量$queried_object = get_queried_object();$taxonomy = $queried_object->taxonomy;$term_id = $queried_object->term_id;$image = get_field('image', $taxonomy . '_' . $term_id);//加载此分类术语的图像(术语对象)echo '<img src="'.$image['sizes']['large'].'"/>';?>

<div class="grid"><header class="unit full-width"><a href="<?php echo home_url(); ?>/" title="Kurdistan Memory Programme" class="logo"><?php bloginfo('name');?></a></标题><footer class="单元二分之一"><h1><?php single_cat_title();?></h1><h4 class="scroll-down">向下滚动以继续</h4></页脚>

</节><主类=网格"><?if ( have_posts() ) : ?><?while ( have_posts() ) : the_post();?><div class="unit col-6-12"><figure class="缩略图"><?如果 ( has_post_thumbnail() ) {the_post_thumbnail();?><图说明><h4><?标题();?></h4><h5><?the_excerpt();?></h5><h6><a href="<?the_permalink(); ?>">查看项目</a></h6></figcaption></图>

<?终了;?><?万一;?></main><?php get_footer();?>

解决方案

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

<?php while ( have_posts() ) : the_post();?><div class="unit col-6-12"><figure class="缩略图"><?php if ( has_post_thumbnail() ) {the_post_thumbnail();?><图说明><h4><?标题();?></h4><h5><?the_excerpt();?></h5><h6><a href="<?the_permalink(); ?>">查看项目</a></h6></figcaption></图>

<?php endwhile;?><?php endif;?>

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

I am using the following wp_query within my taxonomy.php file to try and display the list of posts from within a term from that taxonomy.

I also have 6 taxonomies that I would like this to apply to, and so I would like to make the $args 'taxonomy' => 'topic' and 'terms' => 'arabisation' dynamic, to relate to the current page the user is viewing.

Thanks

<?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 files already run a query that returns the posts with that taxonomy term applied, so try this:

<?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; ?>

The taxonomy.php file will auto-fill your loop, so you just need to use a standard wordpress loop to loop through all of your posts that match the chosen taxonomy term.

这篇关于WP Query taxonomy.php 显示当前词条的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆