I have discovered a useful feature in WordPress that allows the creation of standalone pages which can make use of all the functions available in WordPress. How could we use this feature? Suppose we wanted to create a widget that displays posts’ titles, images and links from our WordPress blog on other web sites but we don’t want to use RSS (Really Simple Syndication). Solution: We can create a standalone page running at your WordPress site that can be inserted into other websites with an iframe.

A Basic Standalone Page

A basic standalone PHP page that can access WordPress functions includes the following:






Stand alone page using wordpress functions







Add a query to display the latest posts

Now how can we add a database query to get the last five posts? We can call a WordPress function, get_posts:

Recent Post

There is no need to open the database, it is open automatically.

Next, let’s add images along with styles and formatting

  
Recent WordPress Blog Posts
"; foreach($posts as $post) { $ThumbnailImage = ""; $recent .= "\n"; $post_title = $post->post_title; $guid = get_permalink($post->ID); $ThumbnailID = get_post_thumbnail_id($post->ID); if($ThumbnailID) { // get the image title $ImageTitle = get_the_title( $ThumbnailID ); // get the url of the file $thumbnail_file = wp_get_attachment_thumb_url($ThumbnailID); // format the image and it’s link $ThumbnailImage = ''. $ImageTitle .''; } // format the line with the image $recent .= '
  • '. $ThumbnailImage . '' . $post_title.'


  • '; } $recent .= ""; echo $recent; ?>

    Our completed widget, which I ran at our WordPress blog at 104.131.90.60, looks like this:

    Be sure to copy and run your widget from the main directory of your WordPress site.

    Display your widget on another web site

    Our widget can now be displayed on another web page using an iframe:

       
    

    You can also add custom functions if you need them in your widget. Just insert them above the html code in the widget file.

    This is just the beginning. What else can we create with standalone pages that can utilize WordPress functions?

    Click here to download the complete widget.