Caleb Jares
Caleb Jares

Reputation: 6307

Embedding a never-ending Wordpress blog in an iframe?

I'm trying to embed a wordpress blog into a page on our website. The actual blog doesn't display 10 posts per page though; it keeps growing when you scroll down, aka. never-ending.

I've tried setting the height to huge amounts, or setting it to auto, but all to no avail. Any ideas?

<iframe src="http://myblog.wordpress.com/" width="100%" height="50000" scrolling="no"></iframe>

Upvotes: 0

Views: 485

Answers (1)

heymega
heymega

Reputation: 9401

Bit of a late answer but someone might find it useful.

I've done the same thing for an existing project. It consisted of the following

  1. Wordpress' XML-RPC APIs
  2. XML-RPC.NET Library
  3. Ajax actionlink to load more posts
  4. Caching

Wordpress' XML-RPC APIs

Have a look at Wordpress' XML-RPC APIs, these allow you to communicate directly with your Wordpress installation. There is a whole list of methods you can use such as getting all posts, adding posts, etc and its quite easy to add your own by modifying some PHP files.

You can find the documentation here

XML-RPC.NET Library

You might have came across XML-RPC if you have done php in the past but its generally not common for .NET developers. So to make life easier I ended up using Charles Cook's XML-RPC.NET library. This handy library creates the remote calls and even deserializes the response.

Heres my code to get posts

public interface IWordPress : IXmlRpcProxy 
{

    [XmlRpcMethod("wp.getPosts")]
    Post[] GetPosts(int blog_id, string username, string password, PostFilter filter);

}


public class PostFilter
{
    //Ignore the first...
    public string offset { get; set; }
    //Bring back this many posts
    public int number { get; set;
}


public struct Post
{
    public string post_id { get; set; }
    public string post_title { get; set; }
    public string post_status { get; set; }
    public DateTime post_date { get; set; }
    public string post_content { get; set; }
    public string post_author { get; set; }

}

Ensure that the property names match those outlined in the Wordpress API documentation otherwise they will not map.

You can find XML-RPC.NET here

Ajax actionlink to load more posts

Like you I wanted to load posts dynamically so I ended up using the Ajax Actionlink to create async requests to my controller, which in turn called the Wordpress APIs.

Here's my code

@Ajax.ActionLink("Load more posts!", "action", "controller", 
    new { offset = Model.Offset },                  
    new AjaxOptions
    {
        InsertionMode = InsertionMode.InsertAfter, 
        UpdateTargetId = "post-items",
        OnSuccess = "loadItemsSucccess",
        OnBegin = "loadItemsBegin"
    }, null)

As you can see I am passing over the offset value which we pass over to the wp.getposts method. It tells the wordpress api to ignore the first x amount. You just need to keep changing this value as posts come in.

Caching

Generally it was quite quick at loading 9 posts at a time, including images, but you should consider doing some form of caching. I ended up just using the standard output cache attribute.

Whilst my solution doesn't use an iframe, I think it gives a bit more flexibility since you have direct control over your data.

Hope this helps.

Upvotes: 1

Related Questions