Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在WordPress页面模板中显示分类法帖子?_Php_Wordpress - Fatal编程技术网

Php 如何在WordPress页面模板中显示分类法帖子?

Php 如何在WordPress页面模板中显示分类法帖子?,php,wordpress,Php,Wordpress,我不确定以前是否有人问过这个问题,但我有点迷路了。我创建了一个新闻编辑室播客,其中包含一个自定义的新闻编辑室类别分类法。新闻编辑室类别有3个字段:新闻稿、媒体、其他。我有一个WordPress页面模板:taxonomy-newsroom\u category.php taxonomy-newsroom_category.php用于显示符合以下条件的Pods帖子: 1 - pods = 'newsroom' 2 - taxonomy = 'press_release' || 'media' ||

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

taxonomy-newsroom_category.php用于显示符合以下条件的Pods帖子:

1 - pods = 'newsroom'
2 - taxonomy = 'press_release' || 'media' || 'others'
我现在的问题是找不到显示帖子详细信息的方法: 图像缩略图、标题栏标题、发布日期

我希望有人能帮忙。谢谢

以下是我当前使用的代码:

<?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表示我创建的分类法中的一个类别值来自select选项中的HTML代码,$args是对数据库的一些查询,$market是我自定义分类法的slug,$wp\U query返回所有筛选帖子

自定义文章类型中我的自定义分类的屏幕截图。如你所见,我有两个小组。第一个在两篇文章中单击,第二个在最后两篇文章中单击。也许这会帮助你发挥想象力看看这个。本文档详细说明了如何使用自定义帖子类型和分类进行查询。你的代码可能是这样的

$args = array(
  'post_type' => 'newsroom',
  'tax_query' => array(
      array(
        'taxonomy' => 'newsroom_category',
        'field'    => 'slug',
        'terms'    => 'press_release',
      ),
  ),
);
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $id = get_the_ID(); // with post id, you can get whatever you want.
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
    /* Restore original Post Data */
    wp_reset_postdata();
} else {
    // no posts found
}

从wordpress文档:

我们有下面的分类法

$args=数组 “tax_query”=>数组 大堆 “分类法”=>“人”, '字段'=>'段塞', “术语”=>“bob” ;
$query=新的WP\u查询$args

分类模板中的代码是什么?谢谢!我还没试过这个。但我还有一个问题,有没有可能不指明具体的术语?例如,如果活动术语等于术语,则显示所有帖子?是的,首先使用获取整个术语列表,然后使用术语列表构建“tax_query”。我已经尝试了您的代码,但它似乎没有为我显示任何内容。谢谢!我试过你的样品,但没有结果。但在其他地方发现了这一点:在我的示例中,我注册了自定义分类法,它有两个类别,但您需要为您的帖子分配一些类别。否则它将返回您自定义帖子类型的所有帖子。。。首先,尝试var_dump$wp_查询是否返回了某些内容为每个帖子分配类别是否与分配分类术语相同?假设我有5篇博文:2篇博文=媒体,1篇博文=其他,2篇博文=新闻发布。这取决于选项值的具体内容。例如,我的选项值是'groupone',所以代码只返回分类类别为'groupone'的帖子。遗憾的是,我现在甚至不能展示任何东西。我现在比以前更迷路了。我一直在不断地搜索和测试其他方法,但其他脚本需要指明具体的术语,我不想这样做,以防其他管理员添加新术语。那么它就不会显示在分类页面中。