XMLRPC: blogger.setTemplate

blogger.setTemplate can be used to set template in blogger. WordPress XMLRPC also supports this, but we couldn’t make use of this
blogger.setTemplate takes the following parameters

  1. blogid
  2. username,
  3. password,
  4. template,
  5. template type

Let’s see the program


/*The URL of the blog*/
$BLOGURL = "http://localhost/wordpress";

function get_response($URL, $context) {
    if(!function_exists('curl_init')) {
    die ("Curl PHP package not installedn");
    /*Initializing CURL*/
    $curlHandle = curl_init();
    /*The URL to be downloaded is set*/
    curl_setopt($curlHandle, CURLOPT_URL, $URL);
    curl_setopt($curlHandle, CURLOPT_HEADER, false);
    curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);
    /*Now execute the CURL, download the URL specified*/
    $response = curl_exec($curlHandle);
    return $response;

/*Creating the blogger.setTemplate request which takes on six parameters
 appkey: ignored (pass some blank value)
 template type
function blogger_setTemplate($appkey,$blogid, $username, $password, $template, $template_type) {
   global $BLOGURL;
   $request = xmlrpc_encode_request("blogger.setTemplate",
      array($appkey, $blogid, $username, $password, $template, $template_type));
    /*Making the request to wordpress XMLRPC of your blog*/
    $xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
    $response = xmlrpc_decode($xmlresponse);
    /*Printing the response on to the console*/

$blogid =1;

$USERNAME = "admin";
$PASSWORD = "check";
$template = "<Blogger><html></html><Blogger>";
$template_type = "main";
blogger_setTemplate($appkey, $blogid, $USERNAME, $PASSWORD, $template, $template_type);
echo "n";

On running this program

$ php blogger.setTemplate.php 
<?xml version="1.0"?>
          <value><string>Either the file is not writable, or something wrong happened. The file has not been updated.</string></value>

We got the above error in WordPress. WordPress doesn’t support the idea of templates, but it supports themes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s