首页 文章

WordPress的 . 循环在模板文件中不起作用

提问于
浏览
0

我已经使用此模板创建了自定义模板并添加了页面 . 但是Loop在那里没有正常工作:Loop返回带有页面id的文章(显然不存在) . 任何人都可以就此提出建议吗?

我在自定义模板中使用的Header.php(循环在index.php上使用此标头正确):

<head>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/styles.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/ptsans.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/ptserif.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/neucha.css" />    
<script type="text/javascript"></script>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
<title><?php wp_title(''); ?><?php if( wp_title('', false) ) { echo ' |'; } ?> <?php bloginfo('name'); ?></title>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_head(); ?>

循环也是基本的:

<?php while ( have_posts() ) : the_post(); ?>

            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <div class="entry-conten clr">
                    <?php the_content(); ?>
                    <?php wp_link_pages( array( 'before' => '<div class="page-links clr">', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
                </div><!-- .entry-content -->

                <footer class="entry-footer">
                    <?php edit_post_link( __( 'Edit Page', 'wpex' ), '<span class="edit-link">', '</span>' ); ?>
                </footer><!-- .entry-footer -->
            </article><!-- #post -->

            <?php comments_template(); ?>
        <?php endwhile; ?>

希望有人能解释我做错了什么 .

1 回答

  • 1

    没有错 . 页面技术上是一个帖子(检查仪表板中的the_ID()),具有不同的模板 . 实际上你可以使用相同的代码 . 也许只是标签不是页面的最佳选择 . 测试尝试最简单的循环

    <?php while ( have_posts() ) : the_post(); the_content(); endwhile; // THE LOOP ?>
    

相关问题