不确定以前是否有人问过这个问题,但我有点迷失。我创建了一个“新闻编辑室”Pod,其中包含新闻编辑室类别的自定义分类法。新闻编辑室类别有 3 个字段:新闻稿、媒体、其他。我有一个 WordPress 页面模板:taxonomy-newsroom_category.php
taxonomy-newsroom_category.php
如果满足以下条件,则用于显示 Pods 帖子:
1 - pods = 'newsroom'
2 - taxonomy = 'press_release' || 'media' || 'others'
我现在的问题是我找不到显示帖子详细信息的方法:image(thumbnail)
, title(post title)
, date_published
我希望有人能帮帮忙。谢谢
这是我当前使用的代码:
<?php
//Setup Pod object
//Presuming permalink structure of example.com/pod-name/item-name
//See http://pods.io/code/pods/find
//Set $params to get 5 items
$params = array(
'limit' => 5,
);
//get current pod name
$pod_name = pods_v( 0, 'newsroom');
//get pods object
$pods = pods( $pod_name, $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
//loop through items using pods::fetch
while ($pods->fetch() ) {
//Put title/ permalink into variables
$post_title = $pods->display('post_title');
$date_published = $pods->display('date_published');
$permalink = site_url( trailingslashit( $pod_name ) . $pods->field('permalink') );
?>
<div class="news-item col-sm-4">
<div class="news-item-img"></div>
<div class="news-item-header">
<h5 class="news-category"></h5>
<h2 class="news-item-title"><a href="<?php echo $permalink; ?>"><?php echo $post_title; ?></a></h2>
<h5 class="news-item-date"><?php echo $date_published; ?></h5>
</div>
</div><!-- close -->
<?php
} //endwhile;
} //endif;
// Output Pagination
//see http://pods.io/docs/code/pods/pagination
echo $pods->pagination( );
?>
我还找到了解决方案......我有我的自定义帖子类型“研究”,我必须根据自定义分类类别来过滤它们。如果您想编写一种分类类别的帖子,请尝试使用类似的内容:
$type = $_GET['type'];
$args = array(
"post_type" => "studien",
"post_per_page" => -1,
"relation" => "AND"
);
if($type != "") {
$args['tax_query'][] = array(
'taxonomy' => 'market',
'field' => 'slug',
'terms' => $type
);
$wp_query = new WP_Query($args);
}
$type
代表我创建的分类法中的一个类别(值来自选择选项中的 HTML 代码),$args
是对数据库的一些查询,“市场”是我的自定义分类法的一部分,$wp_query
返回所有过滤帖子
我的自定义帖子类型中的自定义分类的屏幕截图。正如你所看到的,我有两个组。第一个在两个帖子中被点击,第二个在最后两个帖子中被点击。也许它会帮助你发挥想象力
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)