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 我只想在子类别中显示子类别帖子,但不想在父类别中显示_Php_Wordpress - Fatal编程技术网

Php 我只想在子类别中显示子类别帖子,但不想在父类别中显示

Php 我只想在子类别中显示子类别帖子,但不想在父类别中显示,php,wordpress,Php,Wordpress,问题是类别中的所有帖子都显示在类别和子类别下 但我只想显示该子类别下的帖子,而不是类别中的帖子 所以请任何人给我建议请使用下面的代码。它会帮助你的 <?php $this_category = get_category($cat); ?> <ul style="line-height: 5.7em;"> <?php $id = get_query_var('cat'); $args = array('parent

问题是类别中的所有帖子都显示在类别和子类别下

但我只想显示该子类别下的帖子,而不是类别中的帖子


所以请任何人给我建议

请使用下面的代码。它会帮助你的

<?php $this_category = get_category($cat); ?>
        <ul style="line-height: 5.7em;">
         <?php  $id = get_query_var('cat');
         $args = array('parent' => $id );
         $catdesc = $cat->category_description;
          foreach (get_categories($args) as $cat):?>
              <a href="<?php echo get_category_link($cat->term_id); ?>">
              <img style= "width:250px; height:150px; padding-left:20px; margin-top:20px;" src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
               <div style="display:inline-block;position:absolute;margin-left:-150px;margin-top:150px;"><?php echo ("$cat->cat_name"); ?></div></a>
         <?php endforeach ?>            
         </ul>

Here the code ends for displaying sub category

<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta', '<div class="category-               archive-meta">' . $category_description . '</div>' );
?>
</header>
<?php while ( have_posts() ) : the_post(); ?>
    <?php
           get_template_part( 'content/content', get_post_format() );
        ?>
<?php endwhile; ?>
<?php if($tempera_pagination=="Enable") tempera_pagination(); else tempera_content_nav( 'nav-below' ); ?>
<?php else : ?>
    <article id="post-0" class="post no-results not-found">
        <header class="entry-header">
            <h1 class="entry-title"><?php _e( 'Nothing Found', 'tempera' ); ?></h1>
        </header><!-- .entry-header -->
        <div class="entry-content">
              <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps                          searching will help find a related post.', 'tempera' ); ?></p>
          <?php get_search_form(); ?>
        </div><!-- .entry-content -->
          </article><!-- #post-0 -->
       <?php endif; ?>
        <?php cryout_after_content_hook(); ?>
       </div><!-- #content -->
        <?php tempera_get_sidebar(); ?>
      </section><!-- #primary -->
<?php get_footer(); ?>
<?php $this_category = get_category($cat); ?>
        <ul style="line-height: 5.7em;">
         <?php  $id = get_query_var('cat');
         $args = array('parent' => $id );
         $catdesc = $cat->category_description;
          foreach (get_categories($args) as $cat):?>
              <a href="<?php echo get_category_link($cat->term_id); ?>">
              <img style= "width:250px; height:150px; padding-left:20px; margin-top:20px;" src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
               <div style="display:inline-block;position:absolute;margin-left:-150px;margin-top:150px;"><?php echo ("$cat->cat_name"); ?></div></a>
         <?php endforeach ?>            
         </ul>

Here the code ends for displaying sub category

<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta', '<div class="category-               archive-meta">' . $category_description . '</div>' );
?>
</header>
<?php while ( have_posts() ) : the_post(); ?>
    <?php
           get_template_part( 'content/content', get_post_format() );
        ?>
<?php endwhile; ?>
<?php if($tempera_pagination=="Enable") tempera_pagination(); else tempera_content_nav( 'nav-below' ); ?>
<?php else : ?>
    <article id="post-0" class="post no-results not-found">
        <header class="entry-header">
            <h1 class="entry-title"><?php _e( 'Nothing Found', 'tempera' ); ?></h1>
        </header><!-- .entry-header -->
        <div class="entry-content">
              <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps                          searching will help find a related post.', 'tempera' ); ?></p>
          <?php get_search_form(); ?>
        </div><!-- .entry-content -->
          </article><!-- #post-0 -->
       <?php endif; ?>
        <?php cryout_after_content_hook(); ?>
       </div><!-- #content -->
        <?php tempera_get_sidebar(); ?>
      </section><!-- #primary -->
<?php get_footer(); ?>
$category = '{enter your category name here}';

$categoryID = get_cat_ID($category);

$subcategories = get_categories('child_of=' . $categoryID);

foreach($subcategories as $subcategory) {

   $subcategory_posts = get_posts('cat=' . $subcategory->cat_ID);

   foreach($subcategory_posts as $subcategory_post) {

           $postID = $subcat_post->ID;

           echo get_the_title($postID);
   }
}