Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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_Loops_Archive_Posts - Fatal编程技术网

Php 试图显示“我的存档”页面中的所有帖子,但它仅返回页面内容

Php 试图显示“我的存档”页面中的所有帖子,但它仅返回页面内容,php,wordpress,loops,archive,posts,Php,Wordpress,Loops,Archive,Posts,我在使用have_posts循环显示存档页面中的所有帖子时遇到问题。当我试图返回标题和内容时,它会返回模板页面的标题和内容,而不是帖子的内容 我所做的尝试是运行一个WP_Query post循环,该循环捕获post type=post的所有帖子,并显示内容。唯一的问题是我想要一个动态归档页面,所以当用户选择一个标签时,它会将他们带到一个归档页面,其中包含该标签的所有帖子。因为我正在运行一个特定的WP_查询,所以我的所有归档页面都会显示post type=post的所有帖子 我的猜测是,我必须运行

我在使用have_posts循环显示存档页面中的所有帖子时遇到问题。当我试图返回标题和内容时,它会返回模板页面的标题和内容,而不是帖子的内容

我所做的尝试是运行一个WP_Query post循环,该循环捕获post type=post的所有帖子,并显示内容。唯一的问题是我想要一个动态归档页面,所以当用户选择一个标签时,它会将他们带到一个归档页面,其中包含该标签的所有帖子。因为我正在运行一个特定的WP_查询,所以我的所有归档页面都会显示post type=post的所有帖子

我的猜测是,我必须运行一个简单的have_posts循环,而不是运行WP_查询,这样我的归档页面才会动态

如何设置归档页面:我有一个名为archive.php的文件,我给了归档的模板名,并在wp admin上为其创建了一个页面,并将其命名为Blog

<?php
/**
 * The template for displaying archive pages
 * Template Name: Archives
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

  <div class="d-flex flex-wrap archive-wrap">

   <div class="content-area">
    <main id="main" class="site-main d-flex justify-content-center flex-wrap" role="main">

    <?php // Show the selected frontpage content.
    if ( have_posts() ) :
        while ( have_posts() ) : the_post(); ?>

        <div class="archive-header col-10 d-flex justify-content-center align-items-center flex-column">
            <?php
                the_title( '<h1 class="archive-title">', '</h1>' );
                the_content( '<h1 class="archive-title">', '</h1>'); 
            ?>

        </div><!-- .page-header -->

    <?php

        get_template_part( 'template-parts/post/content', 'archive' );

        endwhile;

        the_posts_pagination( array(
            'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
            'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
        ) );

    endif; ?>

    <div class="col-10 col-md-3 offset-lg-1 sidebar-4-container">
        <?php dynamic_sidebar( 'sidebar-4' ); ?>
    </div>


    </main><!-- #main -->
</div><!-- #primary -->

</div><!-- .wrap -->

<?php get_footer();


尝试使用Query\u posts或get\u posts代替

<?php 
 // the query
 $wpb_all_query = new WP_Query(array('post_type'=>'post', 
 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>

<?php if ( $wpb_all_query->have_posts() ) : ?>


    <!-- the loop -->
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
    <div id="post-<?php the_ID(); ?>" class="col-12 article-container">
        <div class="article-image-div" style="background-image: url('<?php echo get_the_post_thumbnail_url( $post_id, 'large' );  ?> ');"></div>
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>      
        <h5>by <?php echo get_the_author(); ?></h5>
        <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>

        <hr align="left">   
    </div>


    <?php endwhile; ?>
    <!-- end of the loop -->


    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>