How To Display WordPress Blogs over Non-WordPress Websites

Rating: 5.0. From 1 vote.
Please wait...

Hey Friends,

Today I am sharing one of the problems or you can say a learning curve through which I went a few days ago. I was asked to “fetch all the latest blog from one of my client’s blog which was in WordPress to his Corporate website Developed in Core PHP. Since the database for both were different and even on the different server.”

So I needed to find some way where I can request the blog server to send me all the latest blogs as a response. After going through lots of Searching and Analysis I found a simple Optimum Solution which gave me all the blogs from the WordPress site in reverse order i.e Lastest one as the first one.

So Today I want to share my insights and experience with all my newbie developers who may run into the same situation in future or already find it a challenge.

So Lets Start.

There is one very Interesting fact that every WordPress blog has “Atom” named XML file which is kept only to serve the Data to other servers we just need to call it using a PHP function named “simplexml_load_file” which simply loads the XML file and converts the file into Simple XML Element and then all the data can be accessed in OBJECT FORMAT.

Let me show you how.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

$xml=simplexml_load_file("https://YOUR BLOG URL/feed/atom") or die("Error: Cannot create object"); // Load the XML File

$blog=0;

//Now Iterate over the entry upon getting the response
foreach($xml->entry as $blogentry) {

//Show the Time when blog published
$bdate=date('F d, Y', strtotime($blogentry->published));
//Get Blog Title
$btitle=$blogentry->title;
//GET Author Name
$pub_name=$blogentry->author->name;

//Get the Blog Summary
$details=$blogentry->summary;

?>
<div class="col-md-6">

<strong>Title:</strong> <?php echo $btitle;?>
<!--Title with blog link-->

<strong>Published By</strong> <?php echo $pubname;?>
<!--Publisher Name-->
<strong>Published Date</strong> <?php echo $pdate;?>
<!--Published Date-->
<strong>Blog Text</strong> <?php echo $details;?> <!--You Can limit the detail using substr function-->

</div>

<?php
    }
$blogs++;     //Increment the loop
    }
   ?>

So this is How you will get the latest blogs from the blog you desire.

I have Prepared a demo for you free to use just download it and have a look it will serve you the purpose to get demo link Download Here

Hope Mates Our this effort makes your daily challenges easy

Because we believe Hurdles aren’t really Hurdles

Cheers!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *