Hello i have a website and a blog, i want to display my self hosted wordpress blog on my website.
- I want to show only 3 post on my website.
- I want to automatically check for any new post everytime when i reload my website, so that the recent three gets displayed only.
- I want to show the complete title of my wordpress blogpost but specific letters of description.
- Also the description should end up with a word not some piece of non-dictionary word ending with “…”
How this can be done, i have heard that it can be done through RSS.
Can somebody help me?
To accomplish this you need to read the RSS of the blog, from RSS you need to read the Title and the description, after reading the whole description and title you need to trim the description to your desired number of letters. After that you need to check weather the description last word has been completed or not and then you need to remove a the last word if not completed and put the “…”.
First we will make a script to trim the description and to put “…” in last:-
Now we will define the variables in which we store the values:-
Now, we will make an array and store values in it. I am only taking 3 because you have asked it the way. You can change it to anything (The number of post you want to show, put that in the loop)
Now echo all these values, Link is the value where your user will click and he will be taken to your blog:-
FIRST RECENT POST:
SECOND RECENT POST:
THIRD RECENT POST:
Hope this can solve your problem. By the way Nice question.
Click here for the original documentation on displaying RSS feeds with PHP.
Django Anonymous’s
substrwords
function is being used to trim the description and to insert the...
at the end of the description if the it passes the$maxchar
value.Full Code:
blog.php
You can easily put this in a separate PHP file (
blog.php
) and call it inside your actual page.Example:
social.php
Also, this code is plug-n-play friendly.
Why not use the WordPress REST API to retrieve posts –
API URL is : https://public-api.wordpress.com/rest/v1/sites/$site/posts/
where $site is the site id of your wordpress blog
or else simply use this plugin –
http://www.codehandling.com/2013/07/wordpress-feeds-on-your-website-with.html