0

I am trying to get a custom single page to spit out the title and content of the post, the title works fine, the content of the post doesn't seem to want to come through. I don't work much in wordpress so I am in the dark here, can someone tell me how to fix this? Here is my single-news.php code:

<?php get_header(); ?>
<div class="decade1">
<?php

echo get_the_title().'<br/>'; //Output titles of queried posts
echo get_the_content().'<br/>';

?>
</div>
<?php get_footer(); ?>

Thanks!!

Jack Bonneman
  • 1,821
  • 18
  • 24
ajmajmajma
  • 13,712
  • 24
  • 79
  • 133

2 Answers2

0

You need the WordPress Loop before using tags like get_the_title().

<?php get_header(); ?>
<div class="decade1">
  <?php
  if ( have_posts() ) {
    while ( have_posts() ) {
      the_post();
      echo get_the_title() . '<br/>'; 
      echo get_the_content() . '<br/>';
    } // end while
  } // end if
  ?>
</div>
<?php get_footer(); ?>
RRikesh
  • 14,112
  • 5
  • 49
  • 70
0

get_the_content() must be use in loop.

syntax:

get_the_content( $more_link_text, $stripteaser )

where $more_link_text and $stripteaser are optional. read about it

and get_the_title() will output title only when it is in loop, otherwise you have to provide post id to display title.

get_the_title($post_id)
Dinesh
  • 4,066
  • 5
  • 21
  • 35