programing

페이지 내용을 가져오는 올바른 방법

goodjava 2023. 3. 6. 21:07

페이지 내용을 가져오는 올바른 방법

특정 페이지 내용을 취득해야 한다(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(']]>', ']]&gt;', $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