简体   繁体   中英

Wordpress - Can't See Individual Posts

I'm developing a custom WordPress theme for my website, and I've hit a snag. I have a news page which I've set up to display posts. The posts display correctly on the news page, but when I click on the link to the post itself, it comes up totally blank. It takes me to the correct URL, but the post's page is completely white. I've already tried switching to another theme and it displays just fine, and I can't seem to find anyone else online having this problem, so I'm pretty sure it's some really noobish mistake I'm making with my theme.

The code I'm using is pretty basic (this is currently in 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>

For this you have to create a single.php file in your theme folder and paste your code.

<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(); ?>

Would you please create single.php file in your active theme root directory. And copy and paste above code.

I hope it's work for you.

For displaying individual post you need to create single.php file in your theme

Put Below code in your 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; ?>

go though WordPress Template Hierarchy so that you'll get more idea about file structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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