Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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 从自定义帖子类型中列出类别及其帖子_Php_Wordpress_Post_Types_Taxonomy - Fatal编程技术网

Php 从自定义帖子类型中列出类别及其帖子

Php 从自定义帖子类型中列出类别及其帖子,php,wordpress,post,types,taxonomy,Php,Wordpress,Post,Types,Taxonomy,我想显示的类别和他们的职位。(自定义职位类型) 它应该是这样的: <?php $cat_args = array ( 'taxonomy' => 'aundo-cat', ); $categories = get_categories ( $cat_args ); foreach ( $categories as $category ) { $cat_query = null; $args = array ( 'order' => 'ASC', 'orderb

我想显示的类别和他们的职位。(自定义职位类型)

它应该是这样的:

<?php
$cat_args = array (
'taxonomy' => 'aundo-cat',
);
$categories = get_categories ( $cat_args );

foreach ( $categories as $category ) {
$cat_query = null;
$args = array (
    'order' => 'ASC',
    'orderby' => 'title',
    'posts_per_page' => -1,
    'post_type' => 'cdh_aundo',
    'taxonomy' => 'aundo-cat'
    );

$cat_query = new WP_Query( $args );
if ( $cat_query->have_posts() ) {
    echo "<h3>". $category->name ."</h3>";
    echo "<ul>";
    while ( $cat_query->have_posts() ) {
        $cat_query->the_post();
        ?>
        <li>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            <?php if( get_field('aundo_tipp_nummer') ): ?>
                <div class="">
                    <?php the_excerpt(); ?>
                </div>
            <?php endif; ?>
        </li>
        <?php
    }
    echo "</ul>";
}
wp_reset_postdata();
}
?>
第一类

  • A柱(有1类)
  • B柱(有1类)
第2类

  • X柱(具有第2类)
  • 立柱Y(具有第2类)
此时我得到以下输出:

<?php
$cat_args = array (
'taxonomy' => 'aundo-cat',
);
$categories = get_categories ( $cat_args );

foreach ( $categories as $category ) {
$cat_query = null;
$args = array (
    'order' => 'ASC',
    'orderby' => 'title',
    'posts_per_page' => -1,
    'post_type' => 'cdh_aundo',
    'taxonomy' => 'aundo-cat'
    );

$cat_query = new WP_Query( $args );
if ( $cat_query->have_posts() ) {
    echo "<h3>". $category->name ."</h3>";
    echo "<ul>";
    while ( $cat_query->have_posts() ) {
        $cat_query->the_post();
        ?>
        <li>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            <?php if( get_field('aundo_tipp_nummer') ): ?>
                <div class="">
                    <?php the_excerpt(); ?>
                </div>
            <?php endif; ?>
        </li>
        <?php
    }
    echo "</ul>";
}
wp_reset_postdata();
}
?>
第一类

  • A柱(第1类)
  • B柱(第1类)
  • X柱(第2类)
  • 邮政编码Y(第2类)
第2类

  • A柱(第1类)
  • B柱(第1类)
  • X柱(第2类)
  • 邮政编码Y(第2类)
这是我的代码:functions.php

... 
register_taxonomy(
    'aundo-cat',
    'cdh_aundo',
    array(
        'hierarchical' => true,
        'label' => 'Kategorien A und O',
        'query_var' => true,
        'rewrite' => true
        )
    );
...


add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'cdh_aundo',
    array(
        'labels' => array(
            'name' => __( 'A und O' ),
            'singular_name' => __( 'A und O' )
            ),
        'public' => true,
        'has_archive' => false,
        'menu_icon' => 'dashicons-heart',
        'rewrite' => array ('slug' => 'a-und-o-der-unternehmenskommunikation'),
        'supports' => array (
            'title',
            'editor',
            'excerpt',
            'thumbnail',
            'category',
            'custom-fields',
            'revisions' )
        )
    );
}
模板文件中的代码:

<?php
$cat_args = array (
'taxonomy' => 'aundo-cat',
);
$categories = get_categories ( $cat_args );

foreach ( $categories as $category ) {
$cat_query = null;
$args = array (
    'order' => 'ASC',
    'orderby' => 'title',
    'posts_per_page' => -1,
    'post_type' => 'cdh_aundo',
    'taxonomy' => 'aundo-cat'
    );

$cat_query = new WP_Query( $args );
if ( $cat_query->have_posts() ) {
    echo "<h3>". $category->name ."</h3>";
    echo "<ul>";
    while ( $cat_query->have_posts() ) {
        $cat_query->the_post();
        ?>
        <li>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            <?php if( get_field('aundo_tipp_nummer') ): ?>
                <div class="">
                    <?php the_excerpt(); ?>
                </div>
            <?php endif; ?>
        </li>
        <?php
    }
    echo "</ul>";
}
wp_reset_postdata();
}
?>

  • 试试这个:

    $cat_args = array (
        'taxonomy' => 'aundo-cat',
    );
    $categories = get_categories ( $cat_args );
    
    foreach ( $categories as $category ) {
        $cat_query = null;
        $args = array (
            'order' => 'ASC',
            'orderby' => 'title',
            'posts_per_page' => -1,
            'post_type' => 'cdh_aundo',
            'taxonomy' => 'aundo-cat',
            'term' => $category->slug
        );
    
        $cat_query = new WP_Query( $args );
    
        if ( $cat_query->have_posts() ) {
            echo "<h3>". $category->name ."</h3>";
            echo "<ul>";
            while ( $cat_query->have_posts() ) {
                $cat_query->the_post();
                ?>
                <li>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                    <?php if( get_field('aundo_tipp_nummer') ): ?>
                        <div class="">
                            <?php the_excerpt(); ?>
                        </div>
                    <?php endif; ?>
                </li>
                <?php
            }
            echo "</ul>";
        }
        wp_reset_postdata();
    }
    
    $cat_args=数组(
    “分类法”=>“aundo猫”,
    );
    $categories=get\u categories($cat\u args);
    foreach($categories作为$category){
    $cat_query=null;
    $args=数组(
    “订单”=>“ASC”,
    'orderby'=>'title',
    “每页帖子数”=>-1,
    “post_type”=>“cdh_aundo”,
    “分类法”=>“aundo猫”,
    “术语”=>$category->slug
    );
    $cat\u query=新的WP\u查询($args);
    如果($cat\u query->have\u posts()){
    回显“$category->name.”;
    回声“
      ”; while($cat\u query->have\u posts()){ $cat_query->the_post(); ?>
    • 试试这个:

      $cat_args = array (
          'taxonomy' => 'aundo-cat',
      );
      $categories = get_categories ( $cat_args );
      
      foreach ( $categories as $category ) {
          $cat_query = null;
          $args = array (
              'order' => 'ASC',
              'orderby' => 'title',
              'posts_per_page' => -1,
              'post_type' => 'cdh_aundo',
              'taxonomy' => 'aundo-cat',
              'term' => $category->slug
          );
      
          $cat_query = new WP_Query( $args );
      
          if ( $cat_query->have_posts() ) {
              echo "<h3>". $category->name ."</h3>";
              echo "<ul>";
              while ( $cat_query->have_posts() ) {
                  $cat_query->the_post();
                  ?>
                  <li>
                      <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                      <?php if( get_field('aundo_tipp_nummer') ): ?>
                          <div class="">
                              <?php the_excerpt(); ?>
                          </div>
                      <?php endif; ?>
                  </li>
                  <?php
              }
              echo "</ul>";
          }
          wp_reset_postdata();
      }
      
      $cat_args=数组(
      “分类法”=>“aundo猫”,
      );
      $categories=get\u categories($cat\u args);
      foreach($categories作为$category){
      $cat_query=null;
      $args=数组(
      “订单”=>“ASC”,
      'orderby'=>'title',
      “每页帖子数”=>-1,
      “post_type”=>“cdh_aundo”,
      “分类法”=>“aundo猫”,
      “术语”=>$category->slug
      );
      $cat\u query=新的WP\u查询($args);
      如果($cat\u query->have\u posts()){
      回显“$category->name.”;
      回声“
        ”; while($cat\u query->have\u posts()){ $cat_query->the_post(); ?>
      • 你可以这样试试

        
        

        你可以这样试试

        
        

        欢迎来到StackOverflow!您的问题是什么?谢谢:)。问题在上面。我获得了带有帖子的类别,但它显示了所有帖子,而不仅仅是特定类别中的帖子。欢迎来到StackOverflow!您的问题是什么?谢谢:)。问题在上面。我获得了带有帖子的类别,但它显示了我所有帖子,不仅仅是特定猫的帖子。非常感谢!就这样!非常感谢!就这样!