Wordpress 循环并使用 CTP 重复
https://codepen.io/SitePoint/pen/GQoVey
我正在使用找到的选项卡和砌体这里。
我一共有4个类别。 4 个类别 20 个内容
我用 WordPress 打印这个字段没有任何问题。
<main role="main" class="grid">
<div class="row">
<div class="col-md">
<div class="starter-template">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<?php
$args = array(
'type' => 'hizmetler',
'parent' => '',
'orderby' => 'id',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'kategoriler' /* custom post type texonomy name */
);
$cats = get_categories($args);
foreach ($cats as $cat) {
$cat_id= $cat->term_id;
$cat_name= $cat->name; ?>
<li class="tag is-dark">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#<?php echo ''.$cat->term_id.''; ?>" role="tab" aria-controls="<?php echo ''.$cat->term_id.''; ?>" aria-selected="false">
<?php echo ''.$cat->name.''; ?>
</a></li>
<?php wp_reset_postdata(); ?>
<?php } ?>
</ul>
我可以获取类别名称、id 和链接作为 CPT。 问题从这里开始。
我不知道如何循环这个字段。
<div class="tab-content" id="myTabContent">
<div class="tab-pane masonry-container fade show active" id="home" role="tabpanel" aria-labelledby="1-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card with stretched link</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary stretched-link">Go somewhere</a>
</div>
</div>
</div>
循环区域;
<div class="card-body">
<h5 class="card-title">Card with stretched link</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary stretched-link">Go somewhere</a>
</div>
但该字段必须有一个与父div相关的类别名称。
例如:id=“家” 例如: term_id.''; ?>
这就是应该的
<div class="tab-pane masonry-container fade show active" id="EXAMPLE-CAT-ID-1" role="tabpanel" aria-labelledby="EXAMPLE-CAT-ID-1-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">POST 1 TİTLE (cat-1)</h5>
<p class="card-text">POST 1 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 2 TİTLE (cat-1)</h5>
<p class="card-text">POST 2 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 3 TİTLE (cat-1)</h5>
<p class="card-text">POST 3 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
</div>
</div>
<div class="tab-pane masonry-container fade show active" id="EXAMPLE-CAT-ID-2" role="tabpanel" aria-labelledby="EXAMPLE-CAT-ID-2-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">POST 1 TİTLE (cat-2)</h5>
<p class="card-text">POST 1 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 2 TİTLE (cat-2)</h5>
<p class="card-text">POST 2 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 3 TİTLE (cat-2)</h5>
<p class="card-text">POST 3 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
</div>
https://codepen.io/SitePoint/pen/GQoVey
I am using Tabs and Masonry found here.
I have a total of 4 categories. 4 categories 20 contents
I'm printing this field with wordpress without any problems.
<main role="main" class="grid">
<div class="row">
<div class="col-md">
<div class="starter-template">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<?php
$args = array(
'type' => 'hizmetler',
'parent' => '',
'orderby' => 'id',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'kategoriler' /* custom post type texonomy name */
);
$cats = get_categories($args);
foreach ($cats as $cat) {
$cat_id= $cat->term_id;
$cat_name= $cat->name; ?>
<li class="tag is-dark">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#<?php echo ''.$cat->term_id.''; ?>" role="tab" aria-controls="<?php echo ''.$cat->term_id.''; ?>" aria-selected="false">
<?php echo ''.$cat->name.''; ?>
</a></li>
<?php wp_reset_postdata(); ?>
<?php } ?>
</ul>
I can get category name, id and link as CPT.
The problem starts here.
I don't know how to loop this field.
<div class="tab-content" id="myTabContent">
<div class="tab-pane masonry-container fade show active" id="home" role="tabpanel" aria-labelledby="1-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card with stretched link</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary stretched-link">Go somewhere</a>
</div>
</div>
</div>
loop area;
<div class="card-body">
<h5 class="card-title">Card with stretched link</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary stretched-link">Go somewhere</a>
</div>
but this field must have a category name related to the parent div.
ex: id="home"
example: <?php echo ''.$cat->term_id.''; ?>
this is what should be
<div class="tab-pane masonry-container fade show active" id="EXAMPLE-CAT-ID-1" role="tabpanel" aria-labelledby="EXAMPLE-CAT-ID-1-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">POST 1 TİTLE (cat-1)</h5>
<p class="card-text">POST 1 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 2 TİTLE (cat-1)</h5>
<p class="card-text">POST 2 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 3 TİTLE (cat-1)</h5>
<p class="card-text">POST 3 CONTENT</p>
<p class="card-text">CAT 1 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
</div>
</div>
<div class="tab-pane masonry-container fade show active" id="EXAMPLE-CAT-ID-2" role="tabpanel" aria-labelledby="EXAMPLE-CAT-ID-2-tab">
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">POST 1 TİTLE (cat-2)</h5>
<p class="card-text">POST 1 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 2 TİTLE (cat-2)</h5>
<p class="card-text">POST 2 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
<div class="card-body">
<h5 class="card-title">POST 3 TİTLE (cat-2)</h5>
<p class="card-text">POST 3 CONTENT</p>
<p class="card-text">CAT 2 NAME</p>
<a href="#" class="btn btn-primary stretched-link">link Go somewhere</a>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将以下代码放入您的functions.php 文件中。您可以将其用作任何短代码 - [tab_posts] 或
echo do_shortcode('[tab_posts]');
。请记住,当您需要使用选项卡时修复 html。Place the following code in your functions.php file. You can use it as any shortcode - [tab_posts] or
echo do_shortcode('[tab_posts]');
. Just keep in mind to fix html as you need to work your tabs.