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.ww.wp.xz.cn/Pages#Page_Templates
Thread Starter
gallo
(@gallo)
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
(@gallo)
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
*/
?>
The “Template Name” thing at the top is required to make it into a visible Page Template.
More info: http://codex.ww.wp.xz.cn/Pages#Creating_Your_Own_Page_Templates
Edit: Dang. 28 seconds too late.
Thread Starter
gallo
(@gallo)
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.
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
(@gallo)
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
(@gallo)
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.
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.