dongmeixian9665 2015-08-26 19:40
浏览 62
已采纳

Wordpress the_content显示所有页面

So, I'm working through a custom Wordpress theme and have run into a really strange problem, but I can't find the solution. Right now, I have two pages set up with dummy content and one is setup as a static front page. However, the content from both pages is getting pulled onto the homepage.

Here's a link to the live site. wintonsmotionpictures.com

I've been stripping things down to basics to try and locate the problem. This is the content of my page.php file.

<?php
// Filename: page.php
get_header(); ?>

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

<div class="container">
<?php the_content();
 endwhile; endif; 
?>
</div>  

<?php get_footer(); ?>

And this is the HTML content that is getting spit out into Firebug.

<main>
  <section class="wrapper">
    <div class="content-wrap">
      <div class="container">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu est condimentum, dictum nibh vitae, maximus arcu.</p>

        <div class="container">
          <p>Fusce mollis justo vitae porta porta. Proin congue fringilla quam et vehicula. Mauris commodo arcu sit amet neque elementum vestibulum.</p>
        </div>  

      </div>
    </div>
  </section>
</main>

Here also is my header.php file. Again, this whole theme is fairly stripped down.

    <?php
/*
 Filename: header.php
 Author: Jesse Winton
 */
?>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     */
    wp_title( '|', true, 'right' );

    ?></title>

<!-- stylesheets -->
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,700|Merriweather:400,700" rel="stylesheet" type="text/css">
<!-- / stylesheets -->

<!-- scripts -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="<?php bloginfo( 'template_directory' ); ?>/js/modernizr.js" type="text/javascript"></script>
<!-- / scripts -->

<!-- meta tags -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="author" content="Jesse Winton Design"/>
<meta name="robots" content="Index, Follow"/>
<meta name="viewport" content="user-scalable=yes, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />  
<!-- / meta tags -->

<?php wp_head(); ?>

</head>

  <body>

   <?php query_posts(array('post_type'=>'page', 'orderby' => 'menu_order', 'order' => 'ASC')); ?>
                          <?php if(have_posts()): while(have_posts()): the_post(); ?>
                          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                          <?php endwhile; endif; ?> 

    <main>

    <section class="wrapper">
        <div class="content-wrap">

I can't for the life of me locate the problem here. Any ideas would be appreciated.

Thanks,

Jesse

  • 写回答

1条回答 默认 最新

  • dt20081409 2015-08-26 19:49
    关注

    You should not be looping on page.php template. Simply call the_post() once.

    <?php
    // Filename: page.php
    get_header();
    
    the_post(); ?> 
    
    <div class="container">
    <?php the_content(); ?>
    </div>  
    
    <?php get_footer(); ?>
    

    This query within header.php is obstructing the actual post query. Remove it and you'll see the appropriate content in the appropriate places:

       <?php query_posts(array('post_type'=>'page', 'orderby' => 'menu_order', 'order' => 'ASC')); ?>
                              <?php if(have_posts()): while(have_posts()): the_post(); ?>
                              <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                              <?php endwhile; endif; ?> 
    

    You should instead use WP_Query() and wp_reset_postdata();. In the interim, try adding wp_reset_postdata(); as the last line of header.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题
  • ¥15 使用dify通过OpenAI 的API keys添加OpenAI模型时报了“Connection Error”错误
  • ¥40 想找个软件,但我不知道怎么找到它,我甚至不知道有没有
  • ¥15 怎么把60秒的视频时长改成显示0秒?且视频内容没有任何变化的正常播放?目的是为了解决一些平台对视频时长的要求,最好有自动处理的工具!