Jump to content
Sign in to follow this  
Danny

Show latest blog post on Homepage using PHP Exec?

Recommended Posts

Danny

Hi, I want to show the latest blog post on my homepage, I have installed the plugin PHP exec to do this but I'm not sure on what the code is to do so, can anyone help me please? Thanks Dan


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Hi Kate, Yes, I have a static page set as my homepage and so I want to show 1 post from a particular category on the homepage i.e. the lastest post from that category. I have looked at the link you provided and I cant seem to get it to work. I am currently using this but it isnt working how I intend it too.

	<?php
	query_posts( 'posts_per_page=5' );
	
	// the Loop
	while (have_posts()) : the_post();
		the_content( 'Read the full post ?»' );
	endwhile;
	?>

Danny


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Thanks for the link Adam, I tried that and it works but not to the way I intend it to. I am using the following code:

	
    <?php query_posts('showposts=1'); ?> <?php while (have_posts()) : the_post(); ?>
  • "><?php the_title(); ?>
  • <?php the_content(__('(more??¦)')); ?>
  • <?php endwhile;?>
[/code]

And the end result is this: http://img844.imageshack.us/img844/7715/likethisp.jpg But I want it to look like this: http://img833.imageshack.us/img833/4048/insteadthis.jpg Any help would be appreciated. Thanks


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

I know I should be removing the bullets, but if you look at the first image there is a sort of list of that Hello World post, then underneath the actual post, now on image 2 there is no list of the post, only the post itself. Thats how I want it to look, and not sure what I should be changing to get the effect I want.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Kate

Hi Danny, Try this: ` <?php wp_reset_query(); query_posts('showposts=1'); while (have_posts()) : the_post(); the_title(); the_content(); endwhile;?> `

Share this post


Link to post
Share on other sites
Kate

Hmmm... Well, the second post is the one that appears by default on your home page, correct? That was there earlier as well. So, are you wanting to display the latest posts with an offset of 1 (post)?

Share this post


Link to post
Share on other sites
Danny

No I dont think it is a post that appears on my homepage by default, you see when I completely remove the code all I end up with is edit page and nothing else. Basically, I just want to show 1 post, which is the latest post. And thank you for your assistance so far


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
cmunns

Oh then you should just go to your SETTINGS . READING and choose the option for showing posts per page to 1

Share this post


Link to post
Share on other sites
Danny

Although, as soon as I read your reply Adam, I thought thats it, that has to be the problem, it unfortuately didnt solve it :( Im still getting a double Hello world post.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina

If you're getting a double Hello world post, that probably means you have excerpts AND full post content enabled. Check your Blog And Posts settings to make sure that both excerpts and full post content are not enabled at the same time.


Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
Danny

OK, I've disabled all excerpts and full post content settings and it removed all of the second post but the title remains?


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
cmunns

Remember that if you have the posts page as the home page (default) and set to show posts 1 you don't need the custom query loop that you had been working on .

Share this post


Link to post
Share on other sites
Danny

I set my Homepage as the static frontpage and using the feature page template, when I changed it to the post page, I couldnt use any Pagelines meta data, all I got on the page options is use settings. So setting my homepage to post page is not the answer unfortuately. So back to my previous post, is there anyway to remove to simply so one post on the homepage? Again thanks for the support/assistance so far, just really want to get this to work.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Ok, I finally resolved this problem, of showing the 1 latest blog post on the homepage. To do this I used the following code:

	<?php
	query_posts('showposts=1&cat=18');
	while(have_posts()) : the_post();
	?>
	<?php endwhile; ?>

This removes the unwanted double post.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Hmmm... I've ran into another problem, for some reason the php code for showing the latest post is appearing underneath the edit post link and tags. Is there anyway I can but them below the latest post? http://img196.imageshack.us/img196/1314/hmmm2j.jpg


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Kate

Hi Danny, Are we able to get a link to your site, please?

Share this post


Link to post
Share on other sites
cmunns

Are you adding this code via a hook? which one?

Share this post


Link to post
Share on other sites
Danny

Hi Adam, Im sorry but I dont have a clue what you mean lol. Basically, I installed the plugin PHP Exec and Im add this code:

<?php
	query_posts('showposts=1&cat=18');
	while(have_posts()) : the_post();
	?>
	<?php endwhile; ?>

To the page in the page editor, where you normally put your content.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina

Ah, so it's a plugin, not a hook. (Hooks are explained here: http://www.pagelines.com/docs/base-child-theme) PHP cannot be added to the page editor (or post editor). Only HTML is allowed (or regular text if you're using the text editor instead of the HTML editor).


Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×