codememo

WordPress: get_the_content()와 the_content()의 차이

tipmemo 2023. 2. 22. 21:56
반응형

WordPress: get_the_content()와 the_content()의 차이

WordPress에서 새로운 테마를 만들고 get_the_content() 함수로 많은 시간을 보냈습니다.

  <div class="clearfix">
      <div>
        <p><?=get_the_content();?></p>
      </div>
  </div>

단축키나 단락을 처리하지 않는 것 같습니다.

그런 다음 te_content()로 대체했습니다.문단과 바로가기가 작동하기 시작했습니다.

  <div class="clearfix">
      <div>
        <p><?=the_content();?></p>
      </div>
  </div>

질문입니다.함수와 어떤 추가 처리의 차이점이 있습니까?get_the_content();와 비교합니까?

@J Quest는 적절한 답변을 제공했지만, 조금 더 자세히 말씀드리겠습니다.일반적으로 WordPress에는 두 가지 유형의 사후 변수 기능이 있습니다.get_기능 및the_기능들.

get_원하는 정보를 반환하는 등의 함수는 해당 정보를 조작하여 페이지로 인쇄해야 합니다.몇 가지 예:

$content = get_the_content();
$content = apply_filters( 'the_content', $content );
$content = str_replace( 'foo', 'bar', $content );

echo 'Post #'. get_the_ID() . $content;

the_기능(예: 및 실제)echo반환된 값 및 해당되는 경우 해당 값에 대해 "기본 필터"를 적용합니다.이러한 기능은 에코할 필요가 없습니다.

echo get_the_ID();

와 기능적으로 동일하다

the_ID();

다음의 문서를 참조해 주세요.the_ID()말 그대로 가치만 출력한다는 것을 알 수 있을 것이다.get_the_ID()출처:

function the_ID() {
    echo get_the_ID();
}

그런 의미에서, 만약 당신이 이 모든 것들을the_변수로서 기능하기 때문에 페이지 전체에 에코된 변수의 흔적을 남깁니다.

$id = the_ID();
echo 'Post ID: '.$id;

출력:

123Post ID: 123

사용방법get_the_content()숏코드를 실행할 수 있도록 함수로 실행하거나 더 나은 방법으로 실행할 필요가 있습니다.the_content필터링을 실시합니다.

$content = get_the_content();

echo do_shortcode( $content );
// Or:    
echo apply_filters( 'the_content', $content );

템플릿에 투고 내용을 조작하지 않고 뱉기만 하면 일반적으로 (에코 또는 에코 쇼트태그가 없는) 것이 좋습니다.

the_content();

get_the_content()콘텐츠를 전달하지 않습니다.the_content즉, 비디오의 자동 삽입이나 쇼트 코드 확장은 실시하지 않습니다.

그냥 사용하다get_the_content()그러면 태그가 제거됩니다.

https://codex.wordpress.org/Function_Reference/get_the_content https://developer.wordpress.org/reference/functions/the_content/

언급URL : https://stackoverflow.com/questions/50892776/wordpress-difference-between-get-the-content-and-the-content

반응형