Title: PHP code in page contents
Last modified: August 18, 2016

---

# PHP code in page contents

 *  [umeshnair](https://wordpress.org/support/users/umeshnair/)
 * (@umeshnair)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-code-in-page-contents/)
 * Hi,
 * I wish to display the output of a PHP contents in WordPress page, but I cannot
   do that. I can get it displayed in the sidebar, but not in the page.
 * I am trying to put the “Recent posts” in a separate page in wordpress.
 * Any clues?
 * Thanks in advance,
 * – U

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [maerk](https://wordpress.org/support/users/maerk/)
 * (@maerk)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-code-in-page-contents/#post-356146)
 * I expect reading about [The Loop](http://codex.wordpress.org/The_Loop) will help.
 * You’ll also need to link to wp-blog-header.php, something like:
 * `<?php require('wp-blog-header.php'); ?>`
 * Put that before any other code.
 *  [maerk](https://wordpress.org/support/users/maerk/)
 * (@maerk)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-code-in-page-contents/#post-356148)
 * PS you won’t be able to call that from within a WordPress page. You’ll have to
   make a separate .php file.
 * Although you could probably edit your “page” template to do it, and wrap all 
   the “recent post” code in this:
 * `<?php if is_page('recent') {
    /* code goes here (same as what you put in the
   sidebar, most probably) */ } ?>
 * You could then put that in your content div and create a blank page called “recent”.
   That might work, it’s a start anyway 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP code in page contents’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [maerk](https://wordpress.org/support/users/maerk/)
 * Last activity: [20 years, 2 months ago](https://wordpress.org/support/topic/php-code-in-page-contents/#post-356148)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
