Question:
Trying to have my website show latest posts from my wordpress blog? How do i do it?
Photojunkie
2009-09-08 12:01:14 UTC
I have a word press blog and a website. These are two distinct sites. The website is written in PHP and i am trying to get the latest say 5 posts from the blog to appear in a short format in the site? Any suggestions??
Please help!
Three answers:
Mohd Hazwan
2009-09-11 18:42:13 UTC
Simple ways is to pull RSS from your blog.



You can check out here

http://www.feedforall.com/more-php.htm



All the besst :)
Rounder
2009-09-08 12:32:59 UTC
"I have removed the default styling as myself like most people tend to use their own DIVS, h1, h2, etc, and so it's easier to just apply your DIV's and other styling to the core functioning of the code.



$yoursitename_posts_to_show is a numerical variable passed from where you call the function

Change "yoursitename" throughout the function to something unique to avoid dupe var names in Wordpress. I use my site name as Wordpress wont have used it



//DISPLAY LAST X POSTS

function last_xx_posts($yoursitename_posts_to_show){



if (is_numeric($yoursitename_posts_to_show)){



/* gets number of recent posts limited by the number

you assign to the variable */

query_posts('showposts='.$yoursitename_posts_to_show);



if (have_posts()) :



/*

This shows the var (numerical) you set of number of posts to show

If you will ever show only ONE (1) last recent post, you will need

to add some PHP to allow for "Last 1 post" (not "postS")

/*

echo 'Last '.$yoursitename_posts_to_show.' most recent posts';



while (have_posts()) : the_post(); ?>





Comments























By:





Continue Reading - " . the_title('', '', false)."..."); ?>




endwhile; //end loop of all posts

endif; //end if have posts

endif; //end if variable is numeric

}//end function

?>To use this function, copy and paste the above in your wp-content/themes/yourtheme/functions.php file

If you don't have this file you can just make one

Read about that here

http://codex.wordpress.org/Theme_Development#Theme_Functions_File



Then simply use the following code in any of your template files






//show last 5 posts

$yoursitename_posts_to_show = 5;

last_xx_posts($yoursitename_posts_to_show);

?>Set the "5" to however many you want to show.



***IMPORTANT NOTES***



NOTE A

DO NOT call this function with the above code in ANY file where "The_Loop" has already been used.



That is:






while (have_posts()) : the_post(); ?>This includes of course index.php, archive.php, etc

Although, I found I didn't want to anyway as these files already have a bunch of posts, and in single.php the post comments are under the article and that tends to be enough for one page!



Use this code somewhere such as at the bottom of your 404 and perhaps like me you have "pages" like "about this site" that usually

don't have any articles or posts or comments, so using this you can have the last x most recent



NOTE B

THIS WILL override your "Blog pages show at most" setting in Admin -> Settings -> Reading.

So if you set 3 most on one page there, and use the function to display the last 5 posts, it WILL display the last 5 posts!"
mink
2016-12-02 06:02:20 UTC
It sounds such as you will possibly desire to establish an index/dwelling house website. flow to Settings --> examining --> front website reflects - make constructive Your modern-day Posts is chosen. in case you prefer to your wordpress website to be an internet site, with a weblog sub-website, then create a clean website and identify it dwelling house and create a weblog website identify weblog --> then flow back to Settings --> examining --> front website reflects - tick the A Static website decision and set your front website as dwelling house and your weblog website as weblog. attempt that out... sturdy success!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...