Proper way to get page content

后端 未结 8 1681
不思量自难忘°
不思量自难忘° 2020-12-22 19:47

I have to get specific page content (like page(12))

I used that :

  post_content;  ?>


        
相关标签:
8条回答
  • 2020-12-22 20:19

    The wp_trim_words function can limit the characters too by changing the $num_words variable. For anyone who might find useful.

    <?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;  
    ?>
    
    0 讨论(0)
  • 2020-12-22 20:23

    get page content by page name:

    <?php
    $page = get_page_by_title( 'page-name' );
    $content = apply_filters('the_content', $page->post_content); 
    echo $content;
    ?>
    
    0 讨论(0)
  • 2020-12-22 20:23
    $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 you want specific page of content then write in loop

      if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
        {
        echo get_the_ID();
        the_title();
        the_content();
        }
    
    0 讨论(0)
  • 2020-12-22 20:25

    A simple, fast way to get the content by id :

    echo get_post_field('post_content', $id);
    

    And if you want to get the content formatted :

    echo apply_filters('the_content', get_post_field('post_content', $id));
    

    Works with pages, posts & custom posts.

    0 讨论(0)
  • 2020-12-22 20:25

    Just only copy and paste this code it will get your page content.

    <?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;
                    ?>
    
    0 讨论(0)
  • 2020-12-22 20:29

    I used this:

    <?php echo get_post_field('post_content', $post->ID); ?>
    

    and this even more concise:

    <?= get_post_field('post_content', $post->ID) ?>
    
    0 讨论(0)
提交回复
热议问题