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'm new to wordpress and i'm trying to create a website. i need display the content of the pages when corresponding menu items are clicked. my page.php contain

<?php while ( have_posts() ) : the_post(); 
                      $page_data= $post->ID;
                      if($page_data=='116')
                      {
                      ?>    

                      <center><b><h2>WELCOME TO THE CLINIC!!</h2></b></center>
                     <?php 

                      }
                     else{

                     ?>

                      <h1 class="entry-title"><?php the_title(); ?></h1>
                      <?php
                    the_content();

                     }
                      endwhile; ?>

but my content is not displaying. title is showing properly. what is the mistake in the code? please help me.

share|improve this question
    
I don't see a mistake in the code, and it works when I test it (though your markup uses a deprecated/unsupported tag). –  s_ha_dum Oct 30 '13 at 4:29
add comment

3 Answers

Your code is OK, however I think the main failure is to call a page #116, if this page not exist on your WP site the front area or HOME page will not display any data. Normaly to avoid page ID # I use the code if (is_page('name-of-page')) {?>
Some times is better than PAGE ID because the ID number not allways is the same on new WP install, just remember to set your permalinks to pretty using /%permalinks%/

share|improve this answer
    
but sir it is displaying the title correctly. do u have any idea why it is not showing the content? –  user007 Oct 30 '13 at 7:36
    
@user007 try to close each php line and add a div for content: <h1 class="entry-title"> <?php the_title(); ?> </h1> <div class="content"> <?php the_content(); ?> </div> –  Fernando Baltazar Oct 30 '13 at 9:02
    
i already wrote the above whole php code in <div class="content"> sir. i forgot to mention that in here. –  user007 Oct 30 '13 at 9:44
add comment

Perhaps the problem is that either (1) the-content() is being filtered to show nothing or (2) that the content is being sent to the web page, but something is hiding it.

First, make sure there is content to display:

} else {
?>
    <h1 class="entry-title"><?php the_title(); ?></h1>

<?php
    echo 'Before Content';
    echo $post->post_content;
    echo 'After Content';
}

If nothing is hiding the content (like JavaScript or CSS), it should should show up on the page between Before Content and After Content. If not, double check by looking at the browser page source to see if anything was added at that point.

If it shows up, replace echo $post->post_content; with the_content() and reload the page. If the content is being filtered it is probably on the the_content filter. Try removing those filter functions:

} else {
?>
    <h1 class="entry-title"><?php the_title(); ?></h1>
<?php
    remove_all_filters( 'the_content' );
    echo 'Before Content';
    the_content();
    echo 'After Content';
}

Does the content show up now? If it does, there is a filter in the theme or plugin files which is removing the content before it is displayed.

In practice, you would want to find that code and disable it (probably) by removing that faulty filter function. remove_all_filters() is a the drastic option. It can remove filters you want on there. Like filters that add Social Media buttons or helpful links.

share|improve this answer
    
but frnd it is entering into the else part thats why it prints the title properly. but the content i wrote from admin side is not showing. –  user007 Oct 30 '13 at 7:35
    
Sorry. Then something may be filtering the content before it displays. You could try removing those first. I will edit the answer. –  Charles Clarkson Oct 30 '13 at 13:48
add comment

i did it using $post->post_content; that is directly getting and displaying data from database. this works perfect for me.

share|improve this answer
add comment

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.