<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Frank MacDonald&#187; PHP Scripts</title>
	<atom:link href="http://www.frankmacdonald.co.uk/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.frankmacdonald.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 24 Jul 2010 02:56:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Catagory Logic for Wordpress Template</title>
		<link>http://www.frankmacdonald.co.uk/php/catagory-logic-for-wordpress-template.html</link>
		<comments>http://www.frankmacdonald.co.uk/php/catagory-logic-for-wordpress-template.html#comments</comments>
		<pubDate>Sat, 24 Jul 2010 02:54:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[category test]]></category>
		<category><![CDATA[in_category]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[test example]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.frankmacdonald.co.uk/?p=221</guid>
		<description><![CDATA[Sometimes when designing a wordpress site you need to be able to tell specific content where to appear depending on which category is being viewed. This can be achieved using an if statement combined with the in_category test.


Example:


if ( in_category('4') )
{
//do this
}
else if ( in_category('5') )
{
//do this
}
else
{
//do this
}

]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Sometimes when designing a wordpress site you need to be able to tell specific content where to appear depending on which category is being viewed. This can be achieved using an if statement combined with the in_category test.</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p><b>Example:</b></p>
<div class="spacertopRight"></div>
<div class="containerCode">
<code class="php">if ( in_category('4') )<br />
{<br />
//do this<br />
}<br />
else if ( in_category('5') )<br />
{<br />
//do this<br />
}<br />
else<br />
{<br />
//do this<br />
}<br />
</code></div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.frankmacdonald.co.uk/php/catagory-logic-for-wordpress-template.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Post to Wordpress with PHP</title>
		<link>http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html</link>
		<comments>http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html#comments</comments>
		<pubDate>Fri, 11 Dec 2009 02:37:21 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[GNU]]></category>
		<category><![CDATA[keywords]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[XMLRPC]]></category>
		<category><![CDATA[xmlrpc.php]]></category>

		<guid isPermaLink="false">http://www.frankmacdonald.co.uk/?p=71</guid>
		<description><![CDATA[The ability to post to a wordpress blog from any server opens up many possibilities. We can do this with relative ease by using the wordpress XMLRPC API which is built in to every wordpress blog. The following PHP script has been tested with the latest stable version of wordpress (2.8.6) and should work from [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The ability to post to a wordpress blog from any server opens up many possibilities. We can do this with relative ease by using the wordpress XMLRPC API which is built in to every wordpress blog. The following PHP script has been tested with the latest stable version of wordpress (2.8.6) and should work from any webserver with PHP &#038; cURL capability. You must enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols under the reading section of wp-admin. This script is released under the GNU General Public License.</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p><b>Post To Wordpress XMLRPC API with PHP</b></p>
<div class="containerCode">
<code class="php">$title = 'This is the post title';<br />
$body = 'this is the post content';<br />
$rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php';<br />
$username = 'myusername';<br />
$password = 'mypassword';<br />
$category = ''; //default is 1, enter a number here.<br />
$keywords = 'one,two,three';//keywords comma seperated.<br />
$encoding ='UTF-8';//utf8 recommended<br />
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8')<br />
    {<br />
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);<br />
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);<br />
    $content = array(<br />
        'title'=>$title,<br />
        'description'=>$body,<br />
        'mt_allow_comments'=>0,  // 1 to allow comments<br />
        'mt_allow_pings'=>0,  // 1 to allow trackbacks<br />
        'post_type'=>'post',<br />
        'mt_keywords'=>$keywords,<br />
        'categories'=>array($category)<br />
    );<br />
    $params = array(0,$username,$password,$content,true);<br />
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);<br />
    $ch = curl_init();<br />
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);<br />
    curl_setopt($ch, CURLOPT_URL, $rpcurl);<br />
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);<br />
    $results = curl_exec($ch);<br />
    curl_close($ch);<br />
    return $results;<br />
    }<br />
wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords,$encoding);<br />
</code>
</div>
<div class="spacertopRight"></div>
<p>(Noreply, 2009)</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p>This script is easy to configure by simply replacing the example values given in the first lines with some actual data. (The link to xmlrpc.com should be www.yourdomain.com/xmlrpc.php  if your blog resides in the root directory.) Put the whole thing into a PHP file, and run it. (Pekka. 2010)</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p><b>Short explanation of the Parameters in the script</b></p>
<div class="containerCode">
<code class="php">$title = 'This is the post title';<br />
$body = 'this is the post content';<br />
$rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php';<br />
$username = 'myusername';<br />
$password = 'mypassword';<br />
$category = ''; //default is 1, enter a number here.<br />
$keywords = 'one,two,three';//keywords comma seperated.<br />
$encoding ='UTF-8';//utf8 recommended<br />
</code>
</div>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<div class="list">
<ol>
<div class="spacertopRight"></div>
<li>1. $title: The title of the article</li>
<li>2. $body: The body of the article in HTML</li>
<li>3. $rpurl: The url of the XMLRPC api of your blog, in general http://blog_url/xmlrpc.php</li>
<li>4. $username: The username that will post (must have permission to post)</li>
<li>5. $password: The password of the username posting</li>
<li>6. $category: The name of the catagory in which the post will be classified</li>
<li>7. $keywords: The tags (key words) associated with the article in the form of a comma seperated list</li>
<li>8. $encoding: The encoding, by default UTF-8 but you can change it to the parameters of your blog</li>
</ol>
</div>
<div class="spacertopRight"></div>
<p>(Noreply, 2009)</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p><b>Posting Multiple Items</b><br />
If you want to post several items, there are only a few things that change for every post:</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<div class="list">
<ol>
<li>1. The title of the post.</li>
<li>2. The contents of the post</li>
<li>3. The category of the post</li>
<li>4. The keywords (optional).</li>
</ol>
</div>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p>The RPC URL, username, password and encoding is standard if you&#8217;re posting it onto the same website the script resides on. So we only have to store the 4 named items in an array that we can run through. In the following example we store the items in another array, so we have an array of arrays.</p>
<div class="spacertopRight"></div>
<div class="spacertopRight"></div>
<p>You could write something like this:</p>
<div class="containerCode">
<code class="php">// We create a post array that contains an array per post.<br />
// We put in the data index based.<br />
// First item is title,<br />
// Second is content body,<br />
// Third is category, fourth is keywords.<br />
$posts = array(<br />
    array('Title','Contents','category','keywords'),<br />
    array('Another post','More content','another category ID','etc.'),<br />
    // You can add more items if you want.<br />
);<br />
// These are just general settings that are the same for each post.<br />
$rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php';<br />
$username = 'myusername';<br />
$password = 'mypassword';<br />
$encoding ='UTF-8';<br />
foreach($posts AS $Post)<br />
{<br />
    // From the foreach we get an array with post data<br />
    // each cycle. To keep things a bit clear,<br />
    // We will extract the data to seperate variables..<br />
    $title = $Post[0];<br />
    $body = $Post[1];<br />
    $category = $Post[2];<br />
    $keywords = $Post[3];<br />
    wpPostXMLRPC($title,$body,$rpcurl,$username,<br />
$password,$category,$keywords,$encoding);<br />
}<br />
</code>
</div>
<div class="spacertopRight"></div>
<p>(Hans, 2010)</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
