admin管理员组文章数量:1435859
I would like to create a template to display custom post's terms.
First menu level page :
(Drink - About / LOGO / Questions - Contact )
Section 1 (Drink Page) :
(col-6) -> Image / (col-6) -> Page Presentation Text
Section 2 :
(col-4) -> First Term / (col-4) -> Second Term / (col-4) -> Third Term
On click, i would like to display the first post assigned to it's term.
Exemple :
- For the first menu level -> www.mysite/drinks/ On this page, on 2nd section -> First term (Wine), Second Term (Hard), Third Term (Soft)
On click, by example on Hard, i would like somethink like this -> www.mysite/drinks/hard/post-name
--
Currently : - My first menu item, is a PAGE.
When i click on the first term, my url is -> www.mysite/custom-post/post-name and not www.mysite/first-menu-page/post-name
I would likd to use the same template for multiple page, with multiple custom post..
I a junior developper and it's a little bit hard to explain..
Below, my current code :
<!-- SECTION 1 -->
<section class="main-page ptb-60" id="main-page">
<div class="container">
<div class="row">
<div class="col-xl-7 page-content">
<!-- Image -->
<?php
$image = get_field('page_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" class="img-fluid" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
<!-- Image -->
</div>
<div class="col-xl-5">
<!-- Presentation Text -->
<h2><?php the_title(); ?></h2>
<p><?php the_field('page_description'); ?></p>
<hr>
<p class="intro-texte pb-20"><?php the_field('page_introduction'); ?></p>
<p><?php the_field('page_content'); ?></p>
<!-- Presentation Text -->
</div>
</div>
</div>
</section>
<!-- SECTION 1 -->
<!-- SECTION 2 -->
<section class="sous-pages ptb-60 bg-g" id="sous-pages">
<div class="container">
<div class="row ptb-30">
<div class="col-xl-12 d-flex justify-content-center">
<h3><?php the_field('section_title'); ?></h3>
</div>
</div>
<div class="row">
<?php
$taxonomy = get_field('taxonomy');
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) {
$the_query = new WP_Query( array(
"posts_per_page" => 1,
"orderby" => 'date', // this is the default
"order" => 'DESC', // this is the default
"tax_query" => array(
array (
'taxonomy' => $taxonomy, // use the $tax you define at the top of your script
'field' => 'term_id',
'terms' => $term->term_id, // use the current term in your foreach loop
),
),
) ); ?>
<!--LOOP CONTENT -->
<div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 pb-20 cpt-categories">
<div class="cat-images">
<!-- Image -->
<?php
$image = get_field('image_category', $term);
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" class="img-fluid pb-20" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
<!-- Image -->
</div>
<?php $pageone = get_the_permalink($the_query->posts[0]); ?>
<h4><a href="<?php echo $pageone; ?>"><?= $term->name ?></a></h4>
<?php echo $cat; ?>
</div>
<!--LOOP CONTENT -->
<?php
} // End foreach
} // End if
?>
</div>
</div>
</section>
<!-- SECTION 2 -->
I would like to create a template to display custom post's terms.
First menu level page :
(Drink - About / LOGO / Questions - Contact )
Section 1 (Drink Page) :
(col-6) -> Image / (col-6) -> Page Presentation Text
Section 2 :
(col-4) -> First Term / (col-4) -> Second Term / (col-4) -> Third Term
On click, i would like to display the first post assigned to it's term.
Exemple :
- For the first menu level -> www.mysite/drinks/ On this page, on 2nd section -> First term (Wine), Second Term (Hard), Third Term (Soft)
On click, by example on Hard, i would like somethink like this -> www.mysite/drinks/hard/post-name
--
Currently : - My first menu item, is a PAGE.
When i click on the first term, my url is -> www.mysite/custom-post/post-name and not www.mysite/first-menu-page/post-name
I would likd to use the same template for multiple page, with multiple custom post..
I a junior developper and it's a little bit hard to explain..
Below, my current code :
<!-- SECTION 1 -->
<section class="main-page ptb-60" id="main-page">
<div class="container">
<div class="row">
<div class="col-xl-7 page-content">
<!-- Image -->
<?php
$image = get_field('page_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" class="img-fluid" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
<!-- Image -->
</div>
<div class="col-xl-5">
<!-- Presentation Text -->
<h2><?php the_title(); ?></h2>
<p><?php the_field('page_description'); ?></p>
<hr>
<p class="intro-texte pb-20"><?php the_field('page_introduction'); ?></p>
<p><?php the_field('page_content'); ?></p>
<!-- Presentation Text -->
</div>
</div>
</div>
</section>
<!-- SECTION 1 -->
<!-- SECTION 2 -->
<section class="sous-pages ptb-60 bg-g" id="sous-pages">
<div class="container">
<div class="row ptb-30">
<div class="col-xl-12 d-flex justify-content-center">
<h3><?php the_field('section_title'); ?></h3>
</div>
</div>
<div class="row">
<?php
$taxonomy = get_field('taxonomy');
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) {
$the_query = new WP_Query( array(
"posts_per_page" => 1,
"orderby" => 'date', // this is the default
"order" => 'DESC', // this is the default
"tax_query" => array(
array (
'taxonomy' => $taxonomy, // use the $tax you define at the top of your script
'field' => 'term_id',
'terms' => $term->term_id, // use the current term in your foreach loop
),
),
) ); ?>
<!--LOOP CONTENT -->
<div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 pb-20 cpt-categories">
<div class="cat-images">
<!-- Image -->
<?php
$image = get_field('image_category', $term);
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" class="img-fluid pb-20" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
<!-- Image -->
</div>
<?php $pageone = get_the_permalink($the_query->posts[0]); ?>
<h4><a href="<?php echo $pageone; ?>"><?= $term->name ?></a></h4>
<?php echo $cat; ?>
</div>
<!--LOOP CONTENT -->
<?php
} // End foreach
} // End if
?>
</div>
</div>
</section>
<!-- SECTION 2 -->
Share
Improve this question
asked Mar 19, 2019 at 14:36
WDCreativWDCreativ
32 silver badges6 bronze badges
1 Answer
Reset to default 0As you can see in The WordPress Template Hierarchy, you must create a taxonomy template.
Basically, you have two options:
1) taxonomy.php: if all terms share the same design.
2) taxonomy-{slug}.php: if each term has its own design (different colors, layout etc).
本文标签: postsTemplate for displaying CPTTaxonomy URL issues
版权声明:本文标题:posts - Template for displaying CPTTaxonomy URL issues 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675829a2669845.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论