페이지 내용을 가져오는 올바른 방법
특정 페이지 내용을 취득해야 한다(12페이지 등)
나는 그것을 사용했다:
<?php $id=47; $post = get_page($id); echo $post->post_content; ?>
번역과의 호환성을 중시하여 프랑스어 및 영어 텍스트가 모두 반환됩니다.
하지만 루프는 정상입니다. 좋은 언어 버전만 반환하십시오.
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="post">
<?php the_content(); ?>
</div> <!-- .post -->
그래서 질문은...루프 내에서 특정 페이지 내용을 가져오는 방법...
난 내 질문에 답을 했어.불러apply_filter여기 있어.
<?php
$id=47;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
페이지 이름별로 페이지 내용 가져오기:
<?php
$page = get_page_by_title( 'page-name' );
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>
저는 이걸 썼어요
<?php echo get_post_field('post_content', $post->ID); ?>
보다 간결하게 설명하겠습니다.
<?= get_post_field('post_content', $post->ID) ?>
ID를 사용하여 콘텐츠를 쉽고 빠르게 가져오는 방법:
echo get_post_field('post_content', $id);
컨텐츠의 형식을 지정하는 경우는, 다음의 순서에 따릅니다.
echo apply_filters('the_content', get_post_field('post_content', $id));
페이지, 투고, 커스텀 투고에 대응.
이 코드를 복사하여 붙여넣기만 하면 페이지 내용을 얻을 수 있습니다.
<?php
$pageid = get_the_id();
$content_post = get_post($pageid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
wp_trim_words 함수는 $num_words 변수를 변경하여 문자를 제한할 수도 있습니다.유용하다고 생각되는 사람을 위해.
<?php
$id=58;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
$customExcerpt = wp_trim_words( $content, $num_words = 26, $more = '' );
echo $customExcerpt;
?>
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'prev_text' >' Previous','post_type' => 'page', 'posts_per_page' => 5, 'paged' => $paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post();
//get all pages
the_ID();
the_title();
//if you want specific page of content then write
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
endwhile;
//콘텐츠의 특정 페이지를 원하시면 루프에 쓰세요.
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
라이너 1개:
<? if (have_posts()):while(have_posts()): the_post(); the_content(); endwhile; endif; ?>
언급URL : https://stackoverflow.com/questions/5317366/proper-way-to-get-page-content
'programing' 카테고리의 다른 글
| Redx 상태 및 URL 해시 태그 매개 변수를 동기화하는 방법 (0) | 2023.03.06 |
|---|---|
| 테마와 플러그인을 로드하지 않고 WordPress WP-API를 더 빠르게 만듭니다. (0) | 2023.03.06 |
| React의 동적 속성JS (0) | 2023.03.06 |
| Typescript | 함수의 반환 유형 누락에 대한 경고(ESLint (0) | 2023.03.06 |
| 사용자 지정 Wordpress 이미지 크기가 3.5 Media Manager에 표시되지 않음 (0) | 2023.03.06 |