Title: inserting PHP into HTML // using plugin
Last modified: August 19, 2016

---

# inserting PHP into HTML // using plugin

 *  [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/)
 * hello.
 * on one of my pages (not the blog/posts page) i’ve decided to add a line of php
   code that will insert my most recent blog post into that page. i installed the“
   exec-php” plugin so that i could insert the PHP into my HTML page.
 * all is working well, except that the post appears under all other content. i 
   would like to have the post at the top of my page and still be able to add other
   content (html content) under that post.
 * this is what i have put into the HTML of my page:
 *     ```
       Most Recent Post
   
       <?php query_posts('showposts=1'); ?>
   
       This is text. I want this text under the post, but for some reason it's going above the post. see?
       ```
   
 * i’ve tried to add breaklines as well or <p> to break up the lines and put them
   in the order that i’m intending but it didn’t work.
 * any ideas?
 * thanks very much.

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949517)
 * It doesn’t work that way. Even with an exec PHP plugin, you can’t do a query_posts
   and then expect a magic Loop to happen.
 * You’d be better off writing a custom Page Template to pull the latest post and
   wrap your text around that in the template instead.
 * [http://codex.wordpress.org/Pages#Page_Templates](http://codex.wordpress.org/Pages#Page_Templates)
 *  Thread Starter [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949529)
 * thanks otto, that makes sense.
 * i created a new template file and uploaded it to the proper folder. i see it 
   in my wordpress theme editor interface, but i’m not able to “assign” this new
   template to any pages – my new template is not an available option in the “templates”
   drop down menu.
 * fyi – i haven’t done anything to the new template thus far. it’s a duplicate 
   of the pages.php file, just renamed to home.php
 * any ideas?
 * thank you.
 *  Thread Starter [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949533)
 * figured it out.
 * for anyone curious, i was missing something obvious.
 * if you’re creating a new template you must have the following code at the top
   of the code in your new PHP template:
 *     ```
       <?php
       /*
       Template Name: Template Names Goes Here
       */
       ?>
       ```
   
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949534)
 * The “Template Name” thing at the top is required to make it into a visible Page
   Template.
 * More info: [http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates](http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates)
 * Edit: Dang. 28 seconds too late.
 *  Thread Starter [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949538)
 * ya, i was really hoping to beat you on that one and i knew if i did it would 
   only be by a few seconds.
 * i’m having another issue, but perhaps for another thread. if so let me know please.
 * i created my new template and assigned it to my page. done.
 * now the issue is working on the new template php page.
 * i’m trying to add the first post of my blog (posts page) to the top of my non-
   blog page. everything else should be the same as my non-blog pages.
 * here is the code for my new page template:
 *     ```
       <?php
       /*
       Template Name: Home
       */
       ?>
   
       <?php get_header(); ?>
   
       <div id="blog">
   
       <?php require_once (TEMPLATEPATH . '/navigation.php'); ?>
   
       	<div id="main">
   
       	<h2><?php the_title(); ?></h2>
   
       <?php
       query_posts(array('showposts' => 1));
       get_header(); ?>
   
       	<?php
       	global $dlPageId;
       	$dlPageId = null;
       	?>
           <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       		<?php $dlPageId = $post->ID; ?>
       			<?php the_content(); ?>
       	<?php endwhile; endif; ?>
       	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
       	</div>
   
       <?php get_sidebar(); ?>
   
       <?php get_footer(); ?>
       ```
   
 * the blog post is coming up, but that’s it. i have entered some text into the 
   html field in the page editor, so that should be showing itself under the blog
   post..but it is not. i’ve tried putting the code other places inside this php
   page, but with the same result each time.
 * any thoughts? should i delete this reply and make a new thread?
 * thanks.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949556)
 * Put your text into the Template itself, not into the Page content. Your Page 
   content won’t be displaying here, because you’ve pre-empted it with that query_posts.
 *  Thread Starter [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949565)
 * ok, thanks. interesting.
 * i’m straying from WP help at this point so i apologize:
 * after that first recent post, i was hoping to be able to do some HTML coding 
   using tables. i guess this is not possible now since i’m having to do all of 
   my editing inside the php page. is that correct?
 *  Thread Starter [gallo](https://wordpress.org/support/users/gallo/)
 * (@gallo)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949571)
 * i’ve also noticed that with my current code (see above) it’s only calling up 
   the image and text from my ‘most recent post’. it is not calling up the post 
   title, date, or meta information.
 * is there a problem with my query code perhaps?
 * thank you.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949603)
 * No, you just only have it displaying the_content();. If you want the title and
   such, then you need to use the_title(); and the_date(); and so on.
 * Basically, everything after the query_posts will be the new post you just pulled
   instead of your Page.

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

The topic ‘inserting PHP into HTML // using plugin’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/inserting-php-into-html-using-plugin/#post-949603)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
