[英]How can I check if a term has a parent and display that in addition to the current term on taxonomy.php?
[英]WP Query taxonomy.php to display posts from current term
我在我的taxonomy.php
文件中使用以下wp_query
来尝试显示来自该分类法的术语中的帖子列表。
我也有 6 个分类法,我希望将其应用于,因此我想让 $args 'taxonomy' => 'topic'
和'terms' => 'arabisation'
动态'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 循环来遍历与所选分类术语匹配的所有帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.