Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.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/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 WP-如何按页面父类别调用帖子_Php_Wordpress - Fatal编程技术网

Php WP-如何按页面父类别调用帖子

Php WP-如何按页面父类别调用帖子,php,wordpress,Php,Wordpress,我正在为一个具有多个父页面的站点设置博客列表模板,我需要在整个站点中使用此页面模板,不同的页面将需要有自己的博客列表页面。根据父类别调用相关帖子 i、 e: 食物(网站主页) 食品博客(所有食品相关帖子的列表页面) 水果(母版) 水果博客(所有水果相关帖子的列表页面) Veg(父页面) 素食博客(所有素食相关帖子的列表页面) 我的问题是没有调用每个正确父类别的帖子。我得到了所有的帖子 我的代码是这样设置的:非常感谢 <div id="bloglistings">

我正在为一个具有多个父页面的站点设置博客列表模板,我需要在整个站点中使用此页面模板,不同的页面将需要有自己的博客列表页面。根据父类别调用相关帖子

i、 e:

食物(网站主页)

  • 食品博客(所有食品相关帖子的列表页面)
水果(母版)

  • 水果博客(所有水果相关帖子的列表页面)
Veg(父页面)

  • 素食博客(所有素食相关帖子的列表页面)
我的问题是没有调用每个正确父类别的帖子。我得到了所有的帖子

我的代码是这样设置的:非常感谢

<div id="bloglistings">

            <?php wp_reset_query(); ?>

            <?php


            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
            $current_cat = intval( get_query_var('cat') );

            $args = array(
            'post_type'         => 'post',
            'paged'             => $paged,
            'posts_per_page'    => 6,
            'order'             => 'DESC',
            'orderby'           => 'ID',
            );

            $wp_query = new WP_Query( $args );

            if ( $wp_query->have_posts() ) : ?>

            <div class="row">

            <?php $count=0; ?>    
            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <div class="span6">
            <div class="media feature one">
            <a class="pull-left" href="<?php the_permalink(); ?>">
            <?php echo get_the_post_thumbnail($page->ID, 'thumbnail', array('class' => 'img-circle')); ?>
            <img class="hoverimage" src="<?php echo get_template_directory_uri(); ?>/img/icon-read-bloglistings.png" alt="">
            </a>
            <div class="media-body">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p class="date"><?php the_time('F j, Y'); ?></p>
            <p><?php
            $my_excerpt = get_the_excerpt();
            if ( $my_excerpt != '' ) {
            // Some string manipulation performed
            }
            echo $my_excerpt; // Outputs the processed value to the page
            ?>
            </p>
            </div>
            </div>
            </div>

            <?php $count++; ?>

            <?php if ($count==2 ||$wp_query->found_posts==0) : 

            echo '</div><div class="row">';

            ?>

            <?php $count=0; ?>

            <?php endif; ?>
            <?php endwhile; ?>

            <?php else : ?>                
            <h2>Sorry but there are no posts.</h3>
            <?php endif; ?>

            <!-- PAGINATION -->

            <div class="pagination">
            <ul>
            <li>
            <?php
            $big = 999999999; // need an unlikely integer

            echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big
            ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $wp_query->max_num_pages,
            ) );
            ?>
            </li>
            </ul>
            </div>

            <?php wp_reset_query(); ?>


            </div><!-- /.row -->

            </div><!--/bloglistings-->

抱歉,没有帖子。

尝试将类别添加到查询中

替换此项:

 $args = array(
        'post_type'         => 'post',
        'paged'             => $paged,
        'posts_per_page'    => 6,
        'order'             => 'DESC',
        'orderby'           => 'ID',
        );


嗨,ALex,我在发布之前就已经收到了抱歉。当我将“category\uuuu in”包含进来时,它破坏了模板。
 $args = array(
        'post_type'         => 'post',
        'category__in'      => array( $current_cat ),// category was missing here
        'paged'             => $paged,
        'posts_per_page'    => 6,
        'order'             => 'DESC',
        'orderby'           => 'ID',
        );