Nice programing

페이지 콘텐츠를 가져 오는 적절한 방법

nicepro 2020. 12. 31. 23:25
반응형

페이지 콘텐츠를 가져 오는 적절한 방법


특정 페이지 콘텐츠 (예 : page (12))를 가져와야합니다.

나는 그것을 사용했다 :

  <?php $id=47; $post = get_page($id); echo $post->post_content;  ?>

프랑스어 및 영어 텍스트를 반환하는 qtranslate와의 호환성을 위해 좋은 execpt 작업

하지만 루프는 괜찮아, 좋은 언어 버전 만 반환

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

짧막 한 농담:

<? if (have_posts()):while(have_posts()): the_post(); the_content(); endwhile; endif; ?>

ReferenceURL : https://stackoverflow.com/questions/5317366/proper-way-to-get-page-content

반응형