0

I am using get_the_title(453) and while the title displays, i am unable to display the content and the excerpt for the page with the id of 453. The following is my code

        get_the_title(453); 
    $content = get_the_content();
    echo $content;
    the_excerpt();

Is there is something i am missing or doing something wrong?

3 Answers 3

1

I figured it out myself and it worked. Here is the code if anyone need any help.

$the_query = new WP_Query('page_id=1') ;
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
        $the_query->the_post();
        the_title();
        the_content();
        the_excerpt();
    }
} else {
    // no posts found
}
wp_reset_postdata();




Edit:

This is working because the_content() and the_excerpt() have to be used within The Loop.

0

if you are trying to output only specific page title and content with looping, it is ok, you just only need id of post or page // Here is two thing you just need to understand 1. the_title() ( no need "echo", this function is more specific for title of current view post or page); 2. get_the_title( need "echo", this function can show every post or page title in every page);

use 
echo get_the_title(120); // 120 is your post or page id, it can show every page
echo get_the_title($post->ID); // for only current page view
echo get_the_title(get_the_ID()); // for only current page view, also in loop
echo get_the_title(get_the_ID(12)) //120 is your post or page id, it can show every page
echo get_the_title(get_the_ID($post->ID));


content
the_content() is only for current page, also in loop, no need echo 

echo get_the_content(120); // 120 is your post or page id, it can show every page
echo get_the_content($post->ID); // for only current page view
echo get_the_content(get_the_ID()); // for only current page view, also in loop
echo get_the_content(get_the_ID(12)) //120 is your post or page id, it can show every page
echo get_the_content(get_the_ID($post->ID));
0

get_the_title will only retrieve the title of the post you designate. That post data will not carry on to other template tags.

Edit: http://codex.wordpress.org/Function_Reference/get_post should help.

<?php           
 $post_id = 73;
 $queried_post = get_post(69060);
?>
<h1><?php echo $queried_post->post_title; ?>
<p><?php echo $queried_post->post_content; ?></p>
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.