繁体   English   中英

WordPress-看不到个别帖子

[英]Wordpress - Can't See Individual Posts

我正在为我的网站开发自定义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文件,然后粘贴代码。

<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>
<?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文件。 并复制并粘贴上面的代码。

希望对您有用。

为了显示单个帖子,您需要在主题中创建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模板层次结构,以便您对文件结构有更多了解。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM