如何在 WordPress 页面模板中显示分类帖子? [英] How to display posts of taxonomy in WordPress page template?

查看:37
本文介绍了如何在 WordPress 页面模板中显示分类帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定之前是否有人问过这个问题,但我有点迷茫.我创建了一个新闻编辑室"Pod,其中包含新闻编辑室类别的自定义分类法.新闻室类别有 3 个字段:新闻稿、媒体、其他.我有一个 WordPress 页面模板:taxonomy-newsroom_category.php

taxonomy-newsroom_category.php 用于在满足以下条件时显示 Pods 帖子:

1 - pods = 'newsroom'2 - 分类 = 'press_release' ||'媒体' ||'其他'

我现在的问题是找不到显示帖子详细信息的方法:image(thumbnail), title(post title), date_published

希望有人能帮忙.谢谢

这是我目前使用的代码:

5、);//获取当前pod名称$pod_name = pods_v( 0, '新闻室');//获取豆荚对象$pods = pods( $pod_name, $params );//检查返回的总值(给定限制)是否大于零如果 ( $pods->total() > 0 ) {//使用 pods::fetch 循环遍历项目而 ($pods-> fetch() ) {//将标题/永久链接放入变量中$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><!-- 关闭--><?php}//结束;}//万一;//输出分页//见http://pods.io/docs/code/pods/paginationecho $pods->pagination();?>

解决方案

我也找到了解决方案......我有我的自定义帖子类型研究",我必须根据自定义分类类别过滤它们.如果你想写一个分类类别的帖子,尝试使用这样的东西:

$type = $_GET['type'];$args = 数组(post_type" =>"学习",post_per_page" =>-1,关系" =>和");if($type != "") {$args['tax_query'][] = array('分类' =>'市场','字段' =>'蛞蝓','条款' =>$类型);$wp_query = new WP_Query($args);}

$type 代表我创建的分类法中的一个类别(值来自选择选项中的 HTML 代码),$args 是对数据库的一些查询,'market' 是 slug在我的自定义分类法中,$wp_query 返回所有过滤器帖子

我在自定义帖子类型中的自定义分类的屏幕截图.如您所见,我有两个组.在两个帖子中单击第一个,在最后两个帖子中单击第二个.也许它会帮助你发挥想象力

Not sure if this has been asked before, but I'm a bit lost. I've created a "Newsroom" Pods with a custom taxonomy of Newsroom Category. Newsroom Category has 3 fields: Press Release, Media, Others. I have a WordPress page template: taxonomy-newsroom_category.php

taxonomy-newsroom_category.php is used to display Pods posts if meets the following:

1 - pods = 'newsroom'
2 - taxonomy = 'press_release' || 'media' || 'others'

My issue right now is that I can't find a way to display the post details: image(thumbnail), title(post title), date_published

I hope someone can help. Thanks

Here's the code I'm currently using:

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

解决方案

I also found out solution for that... I had my Custom Post Type "studies" and I had to filter them, based on custom taxonomy category. If you want to write Posts of one taxonomy category, try to use something like that:

$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 represents one category in my created Taxonomy (value comes from HTML code in select option), $args Is some query on database and 'market' is slug of my custom Taxonomy, $wp_query returns all filter Posts

screenshot of my custom taxonomy in custom post type. As you can see, I have two groups. First is clicked in two Posts and Second is clicked in last two Posts. Maybe it will helps you to give imagination

这篇关于如何在 WordPress 页面模板中显示分类帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆