【问题标题】:Wordpress - Can't See Individual PostsWordpress - 看不到个别帖子
【发布时间】:2017-01-03 06:07:11
【问题描述】:

我正在为我的网站开发一个自定义 WordPress 主题,但遇到了困难。我有一个新闻页面,我设置它来显示帖子。帖子在新闻页面上正确显示,但是当我单击帖子本身的链接时,它完全空白。它将我带到正确的 URL,但帖子的页面完全是白色的。我已经尝试切换到另一个主题并且它显示得很好,而且我似乎无法在网上找到其他人遇到这个问题,所以我很确定这是我在使用我的主题时犯的一些非常愚蠢的错误。

我使用的代码非常基本(目前在 index.php 中):

<div id="content" class="content_field">

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

        <div id="news_title">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </div>

        <div id="news_body">
            <?php the_content(); ?>
        </div>

    <?php endwhile; ?>

</div>

【问题讨论】:

  • 有single.php吗?
  • 请用single.php在你的主题中创建一个文件,并输入与上面相同的代码
  • 是的,这就是问题所在。非常感谢,我仍然是 WordPress 的初学者,所以新手问题很痛苦!
  • @ZackAkai 你有没有检查过我的代码?

标签: php html wordpress post


【解决方案1】:

为此,您必须在主题文件夹中创建一个single.php 文件并粘贴您的代码。

<div id="content" class="content_field">
<?php while (have_posts()): the_post(); ?>
    <div id="news_title">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
    <div id="news_body">
        <?php the_content(); ?>
    </div>
<?php endwhile; ?>
</div>

【讨论】:

    【解决方案2】:
    <?php
    /**
     * The Template for displaying all single posts
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    get_header(); ?>
    
        <div id="primary" class="site-content">
            <div id="content" role="main">
    
                <?php while ( have_posts() ) : the_post(); ?>
    
                    <div id="news_title">
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </div>
    
                    <div id="news_body">
                        <?php the_content(); ?>
                    </div>
    
                    <nav class="nav-single">
                        <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
                        <span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentytwelve' ) . '</span> %title' ); ?></span>
                        <span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
                    </nav><!-- .nav-single -->
    
                    <?php comments_template( '', true ); ?>
    
                <?php endwhile; // end of the loop. ?>
    
            </div><!-- #content -->
        </div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    您能否在您的活动主题根目录中创建single.php 文件。并复制粘贴上面的代码。

    我希望它对你有用。

    【讨论】:

      【解决方案3】:

      要显示单个帖子,您需要在主题中创建 single.php 文件

      将下面的代码放在你的 Single.php 中:

      <div id="primary" class="content-area">
      <?php while ( have_posts() ) : the_post(); ?>
      <header class="entry-header">
          <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
      </header>
      <div class="entry-content">
      <?php the_content(); ?>
      </div>
      <?php endwhile; ?>
      

      查看WordPress Template Hierarchy,以便您对文件结构有更多了解。

      【讨论】:

        猜你喜欢
        • 2012-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多