Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

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));
share|improve this answer

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>
share|improve this answer
    
it didn't work. –  Nofel Nov 15 '13 at 21:02
    
And it clobbers the main query. Please, please everyone... stop using query_posts. –  s_ha_dum Nov 15 '13 at 22:01
    
s_ha_dum is right. You should always avoid using query_posts. See here: wordpress.stackexchange.com/q/1753/38536 –  Pete Sorensen Nov 16 '13 at 13:32
    
And here: –  s_ha_dum Nov 16 '13 at 14:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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