【问题标题】:Wordpress Single post content not showing upWordpress Single 帖子内容未显示
【发布时间】:2011-06-06 12:30:55
【问题描述】:

我有一个 wordpress 博客主题,它可以很好地显示索引上所有帖子的内容,但是当我点击其中一个帖子时,帖子的内容是空白的,我似乎无法弄清楚为什么。如果我是正确的 single.php 控制该页面。

http://pastebin.com/afLVxMPb = 我的单身.php

我的意思是http://www.ndesign-studio.com/demo/wordpress/blog/how-about-a-blog-post-with-longer-title 的一个例子,但在这个网站上,博客文章的内容确实会显示,但在我的网站上却没有。

我认为问题出在此处......

<div class="entry-content">
      <?php the_content(); ?>
     <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
</div><!-- .entry-content -->

【问题讨论】:

    标签: php html css wordpress wordpress-theming


    【解决方案1】:

    您应该在 single.php 文件中的某处添加“循环”并调用 setup_postdata($post) 或 the_post() 以便您可以访问该循环内的帖子数据。

    在此处阅读有关循环的更多信息:http://codex.wordpress.org/The_Loop

    例如,您的 single.php 文件将如下所示(简化):

    ........
    <div id="content">
        <?php if(have_posts()) : the_post(); ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <h1 class="entry-title"><?php the_title(); ?></h1>
                // etc.. all post info
    
    ............
    
    <?php endforeach; ?>
    

    希望对您有所帮助!祝你好运。

    【讨论】:

    • 但不会“循环”列出我所有的帖子,而不是应该在那里的一个特定的帖子?
    • 不,请注意这里没有 while 循环。不过,您甚至可以添加一个 while 循环,在单个页面上 WP 仍然只会向您显示 1 个帖子。它在单个帖子页面上使用的查询中定义。
    • 你没有,至少没有在 Pastebin 上的 single.php 中。只需尝试在您的 single.php 顶部添加 have_posts() 条件和 the_post() 并亲自查看。
    • 该循环应该存在于任何显示帖子(或自定义帖子类型)的模板文件中,无论您是显示 1 个还是 1000 个帖子,该循环都是模板标签正常工作所必需的,标签如如the_contentthe_title等都依赖它。您可以查看任何默认主题作为示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 2018-02-01
    • 2017-12-04
    • 2011-11-17
    • 2013-12-06
    • 1970-01-01
    相关资源
    最近更新 更多