Jump to content
Sign in to follow this  
Danny

Show latest blog post on Homepage using PHP Exec?

Recommended Posts

Danny

OK, So I have created a new template called Homepage, how would I go about adding a hook to show only one post (latest post) on only the Homepage template underneath the feature slider?


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Ok So I have solved this issue now using Adams hook on this topic but what do I need to add inorder to show the content that add to the page itself, I added this:

<?php the_content(); ?>

But its adding the content above the post, where I want it to be below it.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
kastelic

Try a different hook, like pagelines_inside_bottom_theloop . Go to the Template Setup -> Page Content Area and clikc on advanced setup under Main Content to see the available hooks.

Share this post


Link to post
Share on other sites
Danny

OK so looking at Adam's code which was this:

add_action('pagelines_inside_top_theloop','add_post');
I added this:
add_action('pagelines_inside_bottom_theloop','');

But what should I put where add_post is, on the top piece of code ?


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
kastelic
add_action('pagelines_inside_bottom_theloop','add_post');

The first paramater (pagelines_inside_bottom_theloop) is where your code will go, and the second (add_post) is the name of the function that will contain the code that you need to place. The function of that name generally goes directly after the add_action line.

Share this post


Link to post
Share on other sites
Danny

OK, I'm still struggling with this one, I just cant seem to get the text I've written in the page post area onto the frontpage. I added the following code to the functions.php:

add_action('pagelines_inside_top_theloop','add_post');
	
	function add_post(){?>
	<?php if ( is_front_page() ) { ?>
	<h3 class="hpost">Latest News</h3>
	<?php $my_query = new WP_Query('category_name=blog&showposts=3');
	while ($my_query->have_posts()) : $my_query->the_post(); ?>
	
	<?php
	query_posts('showposts=2&cat=18');
	while(have_posts()) : the_post();
	?>
	
	<?php endwhile; ?>
	<?php endwhile; ?>
	<?php } ?>
	<?php }
	add_action('pagelines_inside_bottom_theloop','add_post');

But nothing shows up? Any suggestions and also how would I go about styling the "latest posts" section of the code with css, currently it looks like this From this To this Now when using Firebug, the div that seems to control as far as I can see is "copy-pad" but when I add this code, it also changes a the look of blog posts too something I dont want, I only want this styling for the homepage latest posts section and nothing more.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina
the text I've written in the page post area
^ Which text is this, specifically?
it also changes a the look of blog posts too something I dont want, I only want this styling for the homepage latest posts section and nothing more.
You'll need to be more specific with your CSS selector so that the CSS only styles what you want. Can you post a link to your site?

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

Hi Catrina, When Im talking about the text, I mean the text you write in the post area of the page where the WYSIWYG is. And here is a link to my test site. http://test.inglorious-basterds.eu/


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina

Add this selector before the CSS you're trying to implement: body.home Your CSS should look something like this:

body.home WHATEVEROTHERSELECTORSYOUHAVEGOHERE {stylinggoeshere...}


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

Great, thats working. Now just to get the text to appear below the latest posts section. I added a bit of greek text to the post area of my homepage and want to display it below the latest post section but cant seem to get it to work. Here is the text I am talking about 2pzwt20.jpg So it looks like this 2ur2m8p.jpg Thanks


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina

In the hook you pasted above, there's this code at the end:

add_action('pagelines_inside_bottom_theloop','add_post');

Is there a reason why it's there (is there content inside that hook)?


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

Yes, basically I thought that was the hook to add the page content below the latest posts section but it doesnt work :D Thats all I need to close this this forum thread now. I'm not really clued up on the hooks as of yet, still a noobie, could you point me in the right direction please Catrina.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
catrina

You're using the same action name (

add_post
) in the hook at the top:
add_action('pagelines_inside_top_theloop','add_post');

That might be the reason why it's not working. I'm not sure if the same action name can applied to two different hooks...


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

Hmmm, thats unfortunate to hear, anyway thanks for you support.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

OK, After messing around, I have finally got something I think, but I have one problem, Im not sure how to get the page content below the actually latest posts. Here is the code I am using

add_action('pagelines_inside_top_theloop','add_post');
	
	function add_post(){?>
	<?php if ( is_front_page() ) { ?>
	
	[b]<?php
	$my_postid = 13;//This is page id or post id
	$content_post = get_post($my_postid);
	$content = $content_post->post_content;
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]>', $content);
	echo $content;
	?>[/b]
	
	<h3 class="hpost">Latest News</h3>
	<?php $my_query = new WP_Query('category_name=news&showposts=3');
	while ($my_query->have_posts()) : $my_query->the_post(); ?>
	
	<?php
	query_posts('showposts=2&cat=5');
	while(have_posts()) : the_post();
	?>
	<?php endwhile; ?>
	<?php endwhile; ?>
	<?php } ?>
	<?php }
	

Now the section highlighed in bold is showing the actually text/information of that page using the WYSIWYG now all I want is to have that part underneath the latest posts section, I have tried numerous things but just keep getting syntax errors on page refresh. Can anyone with more knowledge than me, give me some pointers as to where I'm going wrong. Thannks Danny


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
cmunns

Do you mean that you are having missing page content for EVERYTHING beneath the added code? Seems like your markup is off then but I'm still not exactly sure what you're asking in this case

Share this post


Link to post
Share on other sites
Danny

Hi Adam, basically I have wrote some random text on the page editor using the WYSIWYG and I want to show it underneath the latest posts section. On another issue, while your hear :D, I have the feature on my homepage and it uses the excerpt text, now I want the latest posts to use the more tag rather than excerpt. Is there anyway you could help me change the code to make the latest posts use the more tag rather than the excerpt please! Thanks Danny


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny
You would want the page editor text underneath to show up...based on your hook it already should.
No it doesn't? All I get is the latest posts and nothing more.
Here is how you customize the_content function to use the read more link...(the more tag must be inside the post you're pulling) http://codex.wordpress.org/Function_Reference/the_content#Designating_the_.22More.22_Text
Thanks

Please search our forums, before posting!

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  

×