source

워드프레스: 싱글.php는 _content()를 표시하지 않습니다.

factcode 2023. 2. 17. 21:41
반응형

워드프레스: 싱글.php는 _content()를 표시하지 않습니다.

커스텀 워드프레스 테마를 만들고 있는데 싱글을 얻을 수 없을 것 같아요.php 템플릿이 동작합니다.아래는 제가 작성한 코드입니다.제목은 뜨지만 내용은 뜨지 않는다.왜 그렇지 않은지 짐작 가는 거라도?

<?php
/**
 * The Template for displaying all single posts.
 */

get_header(); ?>

<div id="content" role="main">
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

        <div class="entry">
            <?php the_content(); ?>
        </div>

        <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    </div>
</div><!-- #content -->

출력의 스크린샷에 대해서는, 여기를 참조해 주세요.

여기에 이미지 설명 입력

the_content()는 더 루프 내에 있어야 하기 때문에 표시되지 않습니다.여기서 문서를 참조해 주세요.

코드를 다음과 같이 변경해야 합니다.

if ( have_posts() ) : while ( have_posts() ) : the_post();
  the_content();
endwhile;
else:
  <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
endif;

생략할 수 있습니다.else표시할 콘텐츠가 있다고 확신하는 경우:) 또는 원본 보기만 하면 됩니다.single.php루프가 항상 에워싸고 있다.the_content()

편집:

여기 싱글이 다 있어요.php 사용 / 시작 :

<?php
/**
 * The Template for displaying all single posts.
 */

get_header(); ?>

<div id="content" role="main">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

        <div class="entry">
            <?php the_content(); ?>
        </div>

        <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    </div>
    <?php endwhile; endif; ?>

</div><!-- #content -->

간단히 말해서the_post()위에the_content()그리고 그것은 성공하였다.

저도 비슷한 문제가 있어서 이 글을 씁니다.제 콘텐츠가 안 뜨더라고요.하지만, 제 content에 대한 콜은 The Loop 안에 있었습니다.게다가 이것은, 제 개발 서버에서는 동작하고 있었지만, 프로덕션 서버에서는 동작하고 있지 않았습니다.

모든 플러그인을 제거한 후 하나씩 다시 추가함으로써 이 문제를 해결할 수 있었습니다.

또, 캐시를 유효하게 하고 있는 경우는, 캐시를 클리어 하는 것이 좋습니다.

언급URL : https://stackoverflow.com/questions/8246386/wordpress-single-php-doesnt-display-the-content

반응형