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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的