<?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>Blogging Tips &#187; WordPress Coding &amp; Design</title>
	<atom:link href="http://www.bloggingtips.com/category/wordpress/wordpress-coding-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bloggingtips.com</link>
	<description>Blogging Guides, News, Tips, Resources</description>
	<lastBuildDate>Thu, 18 Mar 2010 16:55:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to stop the blank page after leaving a comment in WordPress?</title>
		<link>http://www.bloggingtips.com/2010/01/05/how-to-stop-the-blank-page-after-leaving-a-comment-in-wordpress/</link>
		<comments>http://www.bloggingtips.com/2010/01/05/how-to-stop-the-blank-page-after-leaving-a-comment-in-wordpress/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 04:39:27 +0000</pubDate>
		<dc:creator>Kevin Muldoon</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=12179</guid>
		<description><![CDATA[After resolving the scheduling bug in WordPress 2.9, I noticed that I was getting sent to a blank page after leaving a comment here. The comment would post but you had to hit the back button and then reload to find this out. I tried a few things the other day but put it to [...]<p><a href="http://www.bloggingtips.com/2010/01/05/how-to-stop-the-blank-page-after-leaving-a-comment-in-wordpress/">How to stop the blank page after leaving a comment in WordPress?</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-11253" title="WordPress" src="http://www.bloggingtips.com/wp-content/uploads/2009/12/wordpress.jpg" alt="WordPress" width="115" height="116" />After <a href="http://www.bloggingtips.com/2010/01/01/how-to-fix-the-missed-schedule-bug-in-wordpress-2-9/">resolving the scheduling bug in WordPress 2.9</a>, I noticed that I was getting sent to a blank page after leaving a comment here. The comment would post but you had to hit the back button and then reload to find this out. I tried a few things the other day but put it to the back of my head until <a href="http://www.robstarr.org/">Rob Starr</a> reminded me about the problem tonight.</p>
<p>Here&#8217;s the problem. After leaving a comment you are sent to http://www.bloggingtips.com/wp-comments-post.php, which is a blank page. If you go back a page and reload then you should see your comment but that page should be redirecting you back to the blog post with your comment on it. </p>
<p>I&#8217;ve only had this problem after updating to WordPress 2.9. However, it&#8217;s clear from reading the WordPress support forums that this is a problem that many people have had for a year or so. My hope was for this article to be an explanation of how you can resolve this problem. Unfortunately, I&#8217;ve not been able to fix it as yet. </p>
<p>If you have had this problem and fixed please share the process you went through to resolve it. I&#8217;m sure many readers, and myself, would be very grateful.</p>
<p>Here are a few steps I have taken to try and resolve this problem. Many people have reported them working for them but none have resolved the issue for me.</p>
<ul>
<li><a href="http://www.crazybulb.com/troubleshoot/wordpress-blank-page-after-posting-a-comment-wp-comment-post-php/">Repaired the comments table via PHPMyAdmin</a></li>
<li><a href="http://www.techpavan.com/2008/12/17/blank-page-comment-submit-wordpress/">Made sure my comments.php template was up to date</a> and removed whitespace from the wp-comments-post.php template</li>
<li>Disabled the Akismet Plugin (Not sure if this is necessary but a few people said it was causing the blank page for them)</li>
<li>Used theme test drive to try out another theme to see if the problem was related to the comments.php code</li>
</ul>
<p>Unfortunately, most of the threads over at WordPress are incomplete with the blogger either not getting his problem resolved, or resolving it and not coming back to explain how he fixed it. </p>
<p>The last thing I can think is causing this is a probllem with database memory. Though if that was the case my other blogs would probably be having this problem too and they&#8217;re not. Plus, it&#8217;s always best to exhaust all other options before going to your host for help as they can&#8217;t be expected to resolve script issues like this.</p>
<p>I do apologise for any inconvenience caused by commentating at the moment. You can leave a comment but you will probably just get sent to that white page so please make sure you hit your back button after submitting your comment.</p>
<p>Again, any feedback on fixing this error would be greatly appreciated. </p>
<p>Thanks,<br />
Kevin</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2010/01/05/how-to-stop-the-blank-page-after-leaving-a-comment-in-wordpress/">How to stop the blank page after leaving a comment in WordPress?</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=12179&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2010/01/05/how-to-stop-the-blank-page-after-leaving-a-comment-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress 2.8 Features</title>
		<link>http://www.bloggingtips.com/2009/06/18/wordpress-2-8-features/</link>
		<comments>http://www.bloggingtips.com/2009/06/18/wordpress-2-8-features/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 19:00:01 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7802</guid>
		<description><![CDATA[WordPress 2.8 has now been released and as always, it&#8217;s a great improvement on the previous version. I&#8217;ve been using it on a couple of sites and so far the biggest improvement has been the theme editor with its colour coding and line numbering.
There are a few other good looking features, the widget interface has [...]<p><a href="http://www.bloggingtips.com/2009/06/18/wordpress-2-8-features/">WordPress 2.8 Features</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.wordpress.org/download/">WordPress 2.8</a> has now been released and as always, it&#8217;s a great improvement on the previous version. I&#8217;ve been using it on a couple of sites and so far the biggest improvement has been the theme editor with its colour coding and line numbering.</p>
<p>There are a few other good looking features, the widget interface has improved greatly and you can now arrange your dashboard into four columns. Under your General settings you can change your timezone to a city in your country and then update for daylight savings which is a major update for those of us who forget!</p>
<p>Finally you can now control how many items are displayed per page in your admin, great for those who want 50 posts on the edit posts page rather than the default 15. To change this you need to go into the page eg. Edit Posts, the click on the Screen Options tab at the top and there you can change it to how ever many you want (it says 20 but there are only 15 there by default, honest!).</p>
<h3>Template Tags</h3>
<p>So how about the new template tags available? There are a few which are listed below. This won&#8217;t seem as major as the 2.7 upgrade where we had <a href="http://www.bloggingtips.com/2008/11/30/wordpress-27-theme-enhancements-ii/">new code for the comment listing</a>, however, the tags below may be of use to some and should help tidy up your code even further in areas.</p>
<dl>
<dt><a href="http://codex.wordpress.org/Template_Tags/the_modified_author">the_modified_author()</a></dt>
<dd>This new tag allows us to display the author who last <em>modified</em> the post. We already have <a href="http://codex.wordpress.org/Template_Tags/the_modified_date">the_modified_date()</a> which displays the date the post was last modified. This is handy if you wanted to display the post date and author as well as the modified date and author, of course more useful for multi author sites.</dd>
<dt><a href="http://codex.wordpress.org/Template_Tags/tag_description">tag_description($tagID);</a></dt>
<dd>This will return the description for the given tag ID, useful if you wanted to output it at the top of your tag theme file.</dd>
<dt><a href="http://codex.wordpress.org/Function_Reference/term_description">term_description($termID, $taxonomy)</a></dt>
<dd>This returns the description of the give term ID for the specified taxonomy. The latter parameter can be &#8216;category&#8217;, &#8216;post_tag&#8217; or &#8216;link_category&#8217;.</dd>
<dt><a href="http://codex.wordpress.org/Function_Reference/wp_lostpassword_url">wp_lostpassword_url($redirect)</a></dt>
<dd>This allows you to insert the Lost Password URL within your page. If you supply a redirect URL then once the lost password is requested the user will be redirected back to the page specified for example, to return the user to the page they were on use the get_permalink() tag eg. <strong>wp_lost_password_url(get_permalink())</strong>.</dd>
<dt><a href="http://codex.wordpress.org/Template_Tags/the_author_meta">the_author_meta($field, $ID)</a></dt>
<dd>This will display an Author&#8217;s meta data stored under the wp_usermeta table. If used with the loop then the $ID can be omitted (if you want that author&#8217;s details). A number of fields to specify are available, the more useful ones in a template being:</p>
<ul>
<li>user_nicename</li>
<li>user_email</li>
<li>user_url</li>
<li>user_registered</li>
<li>display_name</li>
<li>nickname</li>
<li>first_name</li>
<li>last_name</li>
<li>description</li>
<li>jabber</li>
<li>aim</li>
<li>yim</li>
</ul>
<p>If you want to return the data then use <a href="http://codex.wordpress.org/Function_Reference/get_the_author_meta">get_the_author_meta($field, $ID)</a> instead. (Note: this will eventually replace many of the the template tags starting (get_)the_author_. Check the <a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/deprecated.php">deprecated tags list</a> for more info). This tag seems to be similar to <a href="http://codex.wordpress.org/Function_Reference/get_usermeta">get_usermeta()</a>, it just doesn&#8217;t require a user ID specifying.</dd>
</dl>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/06/18/wordpress-2-8-features/">WordPress 2.8 Features</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7802&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/06/18/wordpress-2-8-features/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create Your Own WordPress Widget</title>
		<link>http://www.bloggingtips.com/2009/06/04/create-your-own-wordpress-widget/</link>
		<comments>http://www.bloggingtips.com/2009/06/04/create-your-own-wordpress-widget/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 19:00:45 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7562</guid>
		<description><![CDATA[Widgets make your life easier with sorting out your sidebar in WordPress, however sometimes there&#8217;s information or perhaps an external source/item that you want to turn into a widget but just don&#8217;t know how.
To create a very basic widget it&#8217;s quite simple. We just need to add a function into our functions.php theme file which [...]<p><a href="http://www.bloggingtips.com/2009/06/04/create-your-own-wordpress-widget/">Create Your Own WordPress Widget</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Widgets make your life easier with sorting out your sidebar in WordPress, however sometimes there&#8217;s information or perhaps an external source/item that you want to turn into a widget but just don&#8217;t know how.</p>
<p>To create a very basic widget it&#8217;s quite simple. We just need to add a function into our functions.php theme file which outputs the content, and then register it as a sidebar widget. Sounds easy? It is <img src='http://www.bloggingtips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So, let&#8217;s use our WordPress login form as an example. I&#8217;ve covered how to <a href="http://www.bloggingtips.com/2009/02/15/adding-a-login-box-to-your-site/">add a login box</a> before, so we&#8217;ll take this code as our user code. All we need to do with it is wrap this in a function i.e.</p>
<pre class="brush: php; html-script: true;">&lt;?php
function lbox_widget() {
	if (!is_user_logged_in()) : ?&gt;

&lt;form id=&quot;loginform&quot; action=&quot;&lt;?php echo get_option('home'); ?&gt;/wp-login.php&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;&lt;legend&gt;Login&lt;/legend&gt;
	&lt;div&gt;
		&lt;label for=&quot;log&quot;&gt;Username
		&lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;log&quot; size=&quot;20&quot; /&gt;&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;label for=&quot;pwd&quot;&gt;Password
		&lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;pwd&quot; size=&quot;20&quot; /&gt;&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;label&gt;&lt;input name=&quot;rememberme&quot; type=&quot;checkbox&quot; id=&quot;rememberme&quot; value=&quot;forever&quot; /&gt; Remember Me&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;input type=&quot;submit&quot; name=&quot;wp-submit&quot; id=&quot;wp-submit&quot; value=&quot;Log In&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;redirect_to&quot; value=&quot;&lt;?php echo urlencode(get_permalink()); ?&gt;&quot; /&gt;
	&lt;/div&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;

&lt;?php else : ?&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;&lt;?php echo get_option('home'); ?&gt;/wp-admin/&quot;&gt;WP Admin&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;&lt;?php echo wp_logout_url(get_permalink()); ?&gt;&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

	&lt;?php endif;
} ?&gt;</pre>
<p>Of course at this point you could just use the function call and place that in your sidebar or whereever you wanted it. However, for ease of use, especially if the site isn&#8217;t actually for you but someone who is less clued up on code, we can register it as a widget and then it can just be added to our <a href="http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/">dynamic sidebar</a> in which ever location you want. So to register our function as a widget we use the register_sidebar_widget() function eg.</p>
<pre class="brush: php; html-script: true;">&lt;?php register_sidebar_widget(__('Login Box'), 'lbox_widget'); ?&gt;</pre>
<p>We can place this before or after the function. The first parameter is the name of the widget, which is only seen in the Widgets admin page. The second parameter is the function name for our widget.</p>
<p>If you add all of this code into your functions file then go to your Widgets admin page under Appearance, you should now see a new widget called &#8216;Login Box&#8217;.</p>
<p>That is the basic method, however in our <a href="http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/">widgetise your theme</a> post I also covered about setting the code to go before and after the widget and before and after your heading. We can then pull this into our login box function, so that we set the before and after widget code in the function. To do this we pass the variable <b>$args</b> to our login box function. We then extract this and then we have the array keys set which if you remember were</p>
<pre class="brush: php;">array(
	'before_widget' =&gt; '&lt;li&gt;',
	'after_widget' =&gt; '&lt;/li&gt;',
	'before_title' =&gt; '&lt;h3&gt;',
	'after_title' =&gt; '&lt;/h3&gt;',
);</pre>
<p>So we can then use $before_widget, $after_widget, $before_title and $after_title in our function output if we want. For this function there isn&#8217;t really a title, however we could insert one for logged in users such as &#8216;Welcome Back&#8217;. So to put these changes into practice we now use:</p>
<pre class="brush: php; html-script: true;">&lt;?php
function lbox_widget($args) {
	extract ($args);

	echo $before_widget;
	if (!is_user_logged_in()) : ?&gt;

&lt;form id=&quot;loginform&quot; action=&quot;&lt;?php echo get_option('home'); ?&gt;/wp-login.php&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;&lt;legend&gt;Login&lt;/legend&gt;
	&lt;div&gt;
		&lt;label for=&quot;log&quot;&gt;Username
		&lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;log&quot; size=&quot;20&quot; /&gt;&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;label for=&quot;pwd&quot;&gt;Password
		&lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;pwd&quot; size=&quot;20&quot; /&gt;&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;label&gt;&lt;input name=&quot;rememberme&quot; type=&quot;checkbox&quot; id=&quot;rememberme&quot; value=&quot;forever&quot; /&gt; Remember Me&lt;/label&gt;
	&lt;/div&gt;
	&lt;div&gt;
		&lt;input type=&quot;submit&quot; name=&quot;wp-submit&quot; id=&quot;wp-submit&quot; value=&quot;Log In&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;redirect_to&quot; value=&quot;&lt;?php echo urlencode(get_permalink()); ?&gt;&quot; /&gt;
	&lt;/div&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;

&lt;?php
else :
	echo $before_title.&quot;Welcome Back&quot;.$after_title;
?&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;&lt;?php echo get_option('home'); ?&gt;/wp-admin/&quot;&gt;WP Admin&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;&lt;?php echo wp_logout_url(get_permalink()); ?&gt;&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

	&lt;?php endif;
	echo $after_widget;
}

register_sidebar_widget(__('Login Box'), 'lbox_widget');
?&gt;</pre>
<p>As you can see here, I&#8217;ve passed the variable $args to the function. Then on line 3 I extract these which then allows me to echo them out like standard variables. I&#8217;ve then added the $before_widget variable on line 5 and the $after_widget on line 39. Finally I&#8217;ve inserted our new title in at line 30.</p>
<p>If you update your functions file with that code and then refresh your site (assuming you&#8217;ve added the new widget in already) then you should see the changes. Don&#8217;t forget, you&#8217;ll only see the login box if you&#8217;re not logged in. I recommend using two browsers to see the two different versions (or logging out then back in!).</p>
<p>This is just a simple method for adding your own widgets. You can use this to add any code/script or standard markup of your own.</p>
<p>Next week I&#8217;ll explain how we can change your standard plugin to offer a widget as well, and also how to add options into the widget admin page.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/06/04/create-your-own-wordpress-widget/">Create Your Own WordPress Widget</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7562&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/06/04/create-your-own-wordpress-widget/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Revisiting WordPress Custom Fields</title>
		<link>http://www.bloggingtips.com/2009/05/28/revisiting-wordpress-custom-fields/</link>
		<comments>http://www.bloggingtips.com/2009/05/28/revisiting-wordpress-custom-fields/#comments</comments>
		<pubDate>Thu, 28 May 2009 19:00:38 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7461</guid>
		<description><![CDATA[A few months ago I wrote about Custom Fields in WordPress. At the time I just gave a small example of how these could be used, and a couple of people still didn&#8217;t grasp the point of them so I&#8217;m going to give a few more examples of using them which will hopefully shed some [...]<p><a href="http://www.bloggingtips.com/2009/05/28/revisiting-wordpress-custom-fields/">Revisiting WordPress Custom Fields</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A few months ago I wrote about <a href="http://www.bloggingtips.com/2008/11/02/wordpress-custom-fields/">Custom Fields</a> in WordPress. At the time I just gave a small example of how these could be used, and a couple of people still didn&#8217;t grasp the point of them so I&#8217;m going to give a few more examples of using them which will hopefully shed some light on how useful they actually are!</p>
<p>For the basics of using the custom fields in the admin then please read the <a href="http://www.bloggingtips.com/2008/11/02/wordpress-custom-fields/">custom fields post</a> first. Below are just working examples.</p>
<h3>Meta Description</h3>
<p>Before you mention (or think it), yes there&#8217;s the fantastic All in One SEO pack, but I don&#8217;t use this for my blog as I don&#8217;t need that much extra code running. I don&#8217;t think that this plugin is needed for blog posts however, sometimes a meta description is. So instead of adding a full blown plugin for the benefit of a few pages, we can just use a custom field.</p>
<p>So if you set up a custom field for each post that you want to add a meta description for, give the custom field a name of metad and the value should contain the description. Don&#8217;t forget, once you create the custom field the name will be available automatically for all your other posts and pages.</p>
<p>Then in your header.php file you want to add the meta description tag in. You can either just use</p>
<pre class="brush: php; html-script: true;">&lt;meta name=&quot;description&quot; value=&quot;&lt;?php echo get_post_meta($post-&gt;ID, 'metad', TRUE); ?&gt;&quot; /&gt;</pre>
<p>Or, if you don&#8217;t want an empty description tag if there&#8217;s no description then you can use an if statement with it ie.</p>
<pre class="brush: php; html-script: true;">&lt;?php $metad = get_post_meta($post-&gt;ID, 'metad', TRUE);
if ($metad) : ?&gt;
   &lt;meta name=&quot;description&quot; value=&quot;&lt;?php echo $metad ?&gt;&quot; /&gt;
&lt;?php endif; ?&gt;</pre>
<p>This will only put a description then if one exists for the post or page currently being viewed.</p>
<h3>Post Image</h3>
<p>A lot of bloggers like to add an image to their posts, and whilst this is easily done in the post content area, you could reduce your work by using a custom field. If you create a custom field for a post with a name of postimage and then the value is the URL of the image (you can still upload the image via the image uploader, but instead of inserting it into the post, just copy the URL). We also need some alternative text so create a second field called postimgalt and enter the text for the alt attribute in the value field.</p>
<p>Then in your single.php page (and index.php, archive.php and category.php pages if each exists and you&#8217;re showing full content posts in there) add the image code where you want the image to be placed. For example if you wanted the image to be at the top right of your post then you could use the following just before the template tag the_content();</p>
<pre class="brush: php; html-script: true;">&lt;?php $postimage = get_post_meta($post-&gt;ID, 'postimage', TRUE);
if ($postimage) : ?&gt;
    &lt;img src=&quot;&lt;?php echo $metad ?&gt;&quot; alt=&quot;&lt;?php echo get_post_meta($post-&gt;ID, 'postimgalt', TRUE); ?&gt;&quot; class=&quot;imgright&quot; /&gt;
&lt;?php endif; ?&gt;</pre>
<p>Note the class imgright would then have the styles:</p>
<pre class="brush: css;">.imgright {
    float: right;
    margin: 0 0 10px 10px;
}</pre>
<p>This way you would then just have content in your post and your post image would go into the custom fields.</p>
<h3>Specify the Language</h3>
<p>Last year we created a multilingual site in WordPress for a client, yet still wanted to be able to add the lang and xml:lang attributes to the HTML tag, so we created a custom field called langtype and then used this to insert the correct type ie.</p>
<pre class="brush: php; html-script: true;">&lt;?php
$langtype = get_post_meta($post-&gt;ID, 'langtype', TRUE);
if (empty($langtype)) $langtype = 'en';
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;&lt;?php echo $langtype ?&gt;&quot; lang=&quot;&lt;?php echo $langtype ?&gt;&quot;&gt;
</pre>
<p>This is useful for sites running two or more languages.</p>
<h3>Credit Author</h3>
<p>Sometimes you may have a guest author write for your site. Yes, you can create them an account for this but then that means you need to leave the account there for the lifetime of the blog (on account deletion, the author&#8217;s post will be recredited to the site admin or whoever you select during account deletion). Instead of creating an account for each guest author you have, especially if it&#8217;s only a one off, you can create a custom field to credit the author. So for a guest post, create a field called pauthor, and enter the Author&#8217;s name. If you want to link their name then you can also create a second field called pauthurl and enter the author&#8217;s website (note I&#8217;m just making up fieldnames here. Just make sure they&#8217;re unique and unlikely to clash with anything else already in the database table).</p>
<p>Then in your template files, where it usually says the author&#8217;s name, we can replace this with displaying the guest author, if one exists, else display the post author eg.</p>
<pre class="brush: php; html-script: true;">Post written by:
&lt;?php
$pauthor = get_post_meta ($post-&gt;ID, 'pauthor', TRUE);
if ($pauthor) :
    echo &quot;&lt;a href='&quot;.get_post_meta ($post-&gt;ID, 'pauthurl', TRUE).'&quot;&gt;&quot;.$pauthor.&quot;&lt;/a&gt;&quot;;
else :
    the_author();
endif;
?&gt;</pre>
<p>This would replace your usual &#8220;Post written by: Sarah&#8221; code. Of course each theme is different so you will have to determine what to replace where.</p>
<p>Alternatively you could just add a line at the top of the post if there is a guest author set eg.</p>
<pre class="brush: php; html-script: true;">&lt;?php
$pauthor = get_post_meta ($post-&gt;ID, 'pauthor', TRUE);
if ($pauthor) :
    echo &quot;&lt;p&gt;The following post is a guest post by &lt;a href='&quot;.get_post_meta ($post-&gt;ID, 'pauthurl', TRUE).'&quot;&gt;&quot;.$pauthor.&quot;&lt;/a&gt;.&lt;/p&gt;&quot;;
endif;</pre>
<h3>Conclusion</h3>
<p>Hopefully this has given a few more examples of custom field usage to help you understand how you can use them, or for those who haven&#8217;t seen them before, given you some new ideas on how you can add unique content to your posts and pages without too much effort.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/28/revisiting-wordpress-custom-fields/">Revisiting WordPress Custom Fields</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7461&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/28/revisiting-wordpress-custom-fields/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Get your latest tweets on your blog &#8211; Plugin free</title>
		<link>http://www.bloggingtips.com/2009/05/22/get-your-latest-tweets-on-your-blog-plugin-free/</link>
		<comments>http://www.bloggingtips.com/2009/05/22/get-your-latest-tweets-on-your-blog-plugin-free/#comments</comments>
		<pubDate>Fri, 22 May 2009 19:00:28 +0000</pubDate>
		<dc:creator>Ryan Edmunds</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>
		<category><![CDATA[latest tweets]]></category>
		<category><![CDATA[twitter updates]]></category>
		<category><![CDATA[wp code]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7365</guid>
		<description><![CDATA[There are a lot of plugins for WordPress that deal with Twitter. It can be hard to find the right one when you have a specific feature in mind. Although there are some really useful ones, sometimes a plugin is not always the answer. If you want to add your latest tweets to your blog [...]<p><a href="http://www.bloggingtips.com/2009/05/22/get-your-latest-tweets-on-your-blog-plugin-free/">Get your latest tweets on your blog &#8211; Plugin free</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright" src="http://blog-media.chromaticsites.com/images/post-images/wordpress-plugin-twitter-retweet.jpg" alt="" width="150" height="134" />There are a lot of plugins for WordPress that deal with Twitter. It can be hard to find the right one when you have a specific feature in mind. Although there are some really useful ones, sometimes a plugin is not always the answer. If you want to add your latest tweets to your blog but you don&#8217;t have the resources for another plugin, or you just like doing things by hand, here is some code you can use to add your latest tweets from Twitter to your blog without a plugin.</p>
<p>Everything we need can actually be accomplished in three lines of code.</p>
<p>The first bit of javascript we need to accomplish this is supplied to us by Twitter.</p>
<pre>&lt;script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&amp;count=1"&gt;&lt;/script&gt;</pre>
<p>You&#8217;ll want to change USERNAME to your Twitter username. You can also change count=1 to whatever number of Tweets you want to show up. You are best to put this script somwhere at the bottom of your template. That way if there is any load issues at Twitter your blog page will still load first.</p>
<p>Now all you need is a line of HTML code to display the Tweets.</p>
<pre>&lt;div id="twitter_div"&gt;&lt;ul id="twitter_update_list"&gt;&lt;li&gt;&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;</pre>
<p>It is up to you where you want your Tweets to appear. If your blog is widget-ready you can simply paste this HTML code into a text widget and drag it to the desired location. You can also manually edit sidebar.php or even put it in the header or footer of your blog.</p>
<p>From here you are free to add a new selector to your stylesheet to style the updates. Make a CSS selector with the ID &#8216;twitter_div&#8217; and style it as you see fit.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/22/get-your-latest-tweets-on-your-blog-plugin-free/">Get your latest tweets on your blog &#8211; Plugin free</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7365&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/22/get-your-latest-tweets-on-your-blog-plugin-free/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wordpress Theme Inheritance</title>
		<link>http://www.bloggingtips.com/2009/05/21/wordpress-theme-inheritance/</link>
		<comments>http://www.bloggingtips.com/2009/05/21/wordpress-theme-inheritance/#comments</comments>
		<pubDate>Thu, 21 May 2009 19:00:02 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7348</guid>
		<description><![CDATA[The WordPress template system has a relatively unused gem in the template system, Theme Inheritance. Theme Inheritance allows you to set your theme to inherit files from a parent theme, meaning you could create your theme in the colours you choose, but then you can create a number of new themes with just a stylesheet [...]<p><a href="http://www.bloggingtips.com/2009/05/21/wordpress-theme-inheritance/">Wordpress Theme Inheritance</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The WordPress template system has a relatively unused gem in the template system, Theme Inheritance. Theme Inheritance allows you to set your theme to inherit files from a parent theme, meaning you could create your theme in the colours you choose, but then you can create a number of new themes with just a stylesheet in them, and set each stylesheet to inherit from the main theme, and then just override the styles set.</p>
<p>So, if we use the example of having perhaps 6 different theme styles on one site, and offering user&#8217;s a style switcher to select which one they preferred to see. Often people may just have the 6 themes online, each directory having the index.php theme file, the functions, page, archive, category, single and comments template files. That&#8217;s fine until a new version comes out of WordPress, there are maybe a few new tags you can use, or you decide you want to add a bit of code to say the footer of your site. 6 themes may not be so bad, but if you run a multi author blog, perhaps on WordPress MU, then try changing 6 to 60. Suddenly it&#8217;s not so good!</p>
<p>Our main theme (we&#8217;ll call it &#8216;Parent&#8217;), would consist of all the theme files we need. The typical files being:</p>
<ul>
<li>style.css</li>
<li>index.php</li>
<li>archive.php</li>
<li>single.php</li>
<li>page.php</li>
<li>comments.php</li>
<li>sidebar.php</li>
<li>header.php</li>
<li>footer.php</li>
<li>functions.php</li>
</ul>
<p>Of course you may have additional files as well, but those are a selection of the most common theme files. To define the theme, the style.css file will have the following at the top of it:</p>
<pre class="brush: css;">/*
Theme Name: Parent
Theme URI: http://www.mysite.com/
Description: The default Parent theme from mysite
Version: 1.0
Author: Me
Author URI: http://www.mysite.com/
*/</pre>
<p>We would then put this theme directory in the usual place under /wp-content/themes/.</p>
<p>Now we can move on to creating a child theme. So for example, our parent theme is quite plain, standard letter sizes and black and white. We can then create one child theme that uses a variety of colours, and a second theme that increases the size of the font and allows the site design/layout to work with the increased font size. So for the first child theme we could call this one Rainbow, and tell it to inherit from the parent theme. We would create a new stylesheet for the Rainbow theme, and at the top of style.css we would place</p>
<pre class="brush: css;">/*
Theme Name: Rainbow
Theme URI: http://www.mysite.com/
Description: The Rainbow child theme from mysite
Version: 1.0
Author: Me
Author URI: http://www.mysite.com/
Template: parent
*/</pre>
<p>The additional line in this to tell the theme where to inherit from is the last line &#8216;Template: parent&#8217;. The template name should refer to the directory that the theme is stored in, and it&#8217;s case sensitive.</p>
<p>You can then set all of your styling in this style.css file for the site and upload it to a new theme directory called &#8216;rainbow&#8217;. If you wanted to inherit the styles from the parent theme then you would need to import the parent stylesheet in, then add your own CSS below to override any styles necessary. So you can add:</p>
<p><code>@import url("../parent/style.css");</code></p>
<p>below the top comment in the file.</p>
<p>Then we&#8217;ll create our second stylesheet, for increasing the overall size of the site (yes a well coded site shouldn&#8217;t require a second stylesheet to increase the text size and size of the site, but this is only an example!). This one we&#8217;ll call Large B&#038;W. So again we do the same as above in our new style.css file</p>
<pre class="brush: css;">/*
Theme Name: Large B&amp;W
Theme URI: http://www.mysite.com/
Description: The Large Black and White child theme from mysite
Version: 1.0
Author: Me
Author URI: http://www.mysite.com/
Template: parent
*/
@import url(&quot;../parent/style.css&quot;);</pre>
<p>We then put this into a directory called largebw.</p>
<p>Our themes directory would now look like</p>
<ol>
<li>parent
<ul>
<li>style.css</li>
<li>index.php</li>
<li>archive.php</li>
<li>single.php</li>
<li>page.php</li>
<li>comments.php</li>
<li>sidebar.php</li>
<li>header.php</li>
<li>footer.php</li>
<li>functions.php</li>
</ul>
</li>
<li>rainbow
<ul>
<li>style.css</li>
</ul>
</li>
<li>largebw
<ul>
<li>style.css</li>
</ul>
</li>
</ol>
<p>Up until WordPress 2.7 that was all we could do. It served a purpose, but was obviously limiting in its usefulness for most people. However, since WordPress 2.7, you can now also add PHP theme files in your child directories to override the parent&#8217;s <em>where necessary</em>. So, for example, if you wanted to put an advert in your Large B&#038;W single post theme file for a screen reader, then you would take a copy of the single.php file from the parent theme, add in the additional code for your advert, and then put this into your largebw theme directory. This directory would then have the files style.css and single.php, the other theme files would inherit from the parent directory.</p>
<p>You may still wonder if this is of any use to you. If you decide to purchase a theme (or find one for free at <a href="http://www.wordpress.org/extend/themes/">WordPress</a>) then you would hope that the theme be kept up to date with the newest WordPress additions and functions. Yet, you may want to make some changes to it to suit your own style. Perhaps change the sidebar to use h3 on headings instead of h2, maybe change the header to have a big advert across the top, or maybe add a flickr badge in the footer. However, when the theme is upgraded, you have to do this all again &#8211; which usually means it&#8217;s unlikely you&#8217;ll upgrade your theme! With Theme Inheritance, you can create your child theme to inherit the untouched theme and then you can just copy the files you want to change into it, make your alterations, and leave the rest as normal. Yes you would still have to make a few alterations possibly on upgrading the theme, but it wouldn&#8217;t be as much hassle.</p>
<p>So, hopefully now you can see the potential for using child themes on your site, regardless of whether you have one theme or many, it has a use that is not widely used yet but I&#8217;m sure will be in the future <img src='http://www.bloggingtips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/21/wordpress-theme-inheritance/">Wordpress Theme Inheritance</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7348&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/21/wordpress-theme-inheritance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding custom icons to your WordPress theme</title>
		<link>http://www.bloggingtips.com/2009/05/20/adding-custom-icons-to-your-wordpress-theme/</link>
		<comments>http://www.bloggingtips.com/2009/05/20/adding-custom-icons-to-your-wordpress-theme/#comments</comments>
		<pubDate>Wed, 20 May 2009 14:00:24 +0000</pubDate>
		<dc:creator>Ryan Edmunds</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7303</guid>
		<description><![CDATA[If you are using a WP framework it is quite simple to modify the background images and icons set up with the theme. Some of the more powerful themes even allow you to upload new images from right inside the admin area.  However, if you&#8217;re using something a little simpler, most of the time you [...]<p><a href="http://www.bloggingtips.com/2009/05/20/adding-custom-icons-to-your-wordpress-theme/">Adding custom icons to your WordPress theme</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you are using a <a href="http://www.bloggingtips.com/2009/05/15/wordpress-theme-frameworks/">WP framework</a> it is quite simple to modify the background images and icons set up with the theme. Some of the more powerful themes even allow you to upload new images from right inside the admin area.  However, if you&#8217;re using something a little simpler, most of the time you have to go in and manually add images to your theme the old fashioned way. If your theme falls under the latter, we&#8217;ve got the quick and dirty guide you need to add custom icons or images to your WordPress theme.</p>
<p><img class="alignnone" src="http://wphacks.com/wp-content/uploads/2008/05/web-icons.png" alt="" width="414" height="377" /></p>
<p><strong>You Will Need</strong>:</p>
<ul>
<li>Basic HTML Knowledge</li>
<li>An FTP Client</li>
<li>No Fear of PHP Code</li>
</ul>
<p>In order to add images to your theme you will need to first create a folder within your current wp-themes folder called images. Unless it already has one, in which case it would be found in your wp-folder/WP-Content/WP-Themes/YourTheme/images.</p>
<p>Using your favorite FTP Client ( I like leech FTP ) upload any images that you want to use in your theme. If you just want to replace the images that come stock with your WordPress theme you can probably get away with simply renaming your new images to overwrite the ones in your current theme images folder. If you&#8217;re adding images to place they didn&#8217;t exist before, read on.</p>
<p><strong>Grabbing the directory with WordPress template tags</strong></p>
<p>You can use a WP template tag to refer to the current theme&#8217;s directory without having to type out the entire URL. This is the most compatable way as it uses a dynamic reference to the directory, and will work on any installation.</p>
<pre>&lt;?php bloginfo('template_url');?&gt;</pre>
<p>This will simply get you into the directory of whatever theme is currently active. Now lets look at two ways to implement and image from this folder.</p>
<p>First  we&#8217;ll look at getting a background image from this directory, then a static image that could be served as a logo or an icon elsewhere in the theme.</p>
<p>In your stylesheet:</p>
<pre>body{
background-image: url(&lt;?php bloginfo('template_url');?&gt;/images/my-image.gif);
}</pre>
<p>The code above simply looks for a specific image inside the images folder within your theme. The second code will do the same, but will populate a normal HTML image code.</p>
<pre>&lt;img src="&lt;?php bloginfo('template_url');?&gt;/images/my-image.gif" alt="my icon"/&gt;</pre>
<p>You should know feel relatively safe adding your own images to any WordPress theme.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/20/adding-custom-icons-to-your-wordpress-theme/">Adding custom icons to your WordPress theme</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7303&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/20/adding-custom-icons-to-your-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Widgetise Your Theme Part II</title>
		<link>http://www.bloggingtips.com/2009/05/14/widgetise-your-theme-part-ii/</link>
		<comments>http://www.bloggingtips.com/2009/05/14/widgetise-your-theme-part-ii/#comments</comments>
		<pubDate>Thu, 14 May 2009 19:00:46 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7179</guid>
		<description><![CDATA[Last week I wrote about how to widgetise your theme, and explained how to turn your sidebar into a dynamic sidebar, allowing you to add widgets from within your admin panel, rather than manually coding them into the sidebar. We can now take this one step further and create multiple sidebars/widget &#8216;blocks&#8217;. These don&#8217;t have [...]<p><a href="http://www.bloggingtips.com/2009/05/14/widgetise-your-theme-part-ii/">Widgetise Your Theme Part II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote about how to <a href="http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/">widgetise your theme</a>, and explained how to turn your sidebar into a dynamic sidebar, allowing you to add widgets from within your admin panel, rather than manually coding them into the sidebar. We can now take this one step further and create multiple sidebars/widget &#8216;blocks&#8217;. These don&#8217;t have to always be a full length sidebar, they could be two or three sections in the footer of your site, or perhaps you want a left and right sidebar, or two next to each other. Once they&#8217;re set up however, all you need to do is add the widgets you require to each section. You could even create two different types depending on which section of the site you&#8217;re on, using <a href="http://www.bloggingtips.com/2008/06/29/using-conditional-tags/">conditionals</a></p>
<p>So last week we used the basic code in our functions file of:</p>
<pre class="brush: php;">if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'before_widget' =&gt; '&lt;li&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;'
    ));
}</pre>
<p>To create multiple sidebars we first need to add the name key into our array to allow us to distinguish between the different registered sidebars. This is a fairly simple change e.g.</p>
<pre class="brush: php;">if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' =&gt; 'Right Sidebar',
        'before_widget' =&gt; '&lt;li&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;'
    ));
}</pre>
<h3>Multiple Sidebars</h3>
<p>To then create a second sidebar you just use a different name for each. You can also change the before and after keys too eg.</p>
<pre class="brush: php;">if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' =&gt; 'Right Sidebar',
        'before_widget' =&gt; '&lt;li&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;'
    ));
    register_sidebar(array(
        'name' =&gt; 'Footer',
        'before_widget' =&gt; '&lt;div class=&quot;footer_widget&quot;&gt;',
        'after_widget' =&gt; '&lt;/div&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;'
    ));
}</pre>
<p>When you then want to call a sidebar you need to alter the code in your theme file to include the sidebar name as a parameter of the function dynamic_sidebar() eg.</p>
<pre class="brush: php;">if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer')) :
    // enter HTML code here for items such as recent comments, recent posts etc.
endif;</pre>
<p>We use the register_sidebar() function if we want to give very different names to each sidebar and/or change the before and after code. However, there is also the register_sidebars() function, which can reduce code, providing certain elements are to remain the same. To use the register_sidebars() function we tell the function how many sidebars to register eg.</p>
<pre class="brush: php;">if (function_exists('register_sidebars')) {
    register_sidebars(2, array('name' =&gt; 'Sidebar %d'));
}</pre>
<p>This would create two sidebars with the names Sidebar 1 and Sidebar 2. This is an okay solution if you only intend to have maybe a couple of sidebars and you know which one goes where, however for ease of use I would recommend the first method and assign more precise names. Plus if you intend to give your theme away or sell it, then whilst you may know which sidebar is which, the user may not!</p>
<h3>Adding Widgets</h3>
<p>Now when you go to your Widgets section under Appearance, in the admin, you&#8217;ll have a drop down to select which sidebar to add the widget to. This allows you to set up each dynamic sidebar easily.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/14/widgetise-your-theme-part-ii/">Widgetise Your Theme Part II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7179&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/14/widgetise-your-theme-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Widgetise Your Theme</title>
		<link>http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/</link>
		<comments>http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:00:32 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=7031</guid>
		<description><![CDATA[If you want to use widgets in your WordPress theme, or you&#8217;re a theme developer and want to make your theme &#8216;widget ready&#8217;, then all it takes is a couple of steps to add the necessary code in and your theme is good to go.
The Function
First we need to register the sidebar in our functions.php [...]<p><a href="http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/">Widgetise Your Theme</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you want to use widgets in your WordPress theme, or you&#8217;re a theme developer and want to make your theme &#8216;widget ready&#8217;, then all it takes is a couple of steps to add the necessary code in and your theme is good to go.</p>
<h3>The Function</h3>
<p>First we need to register the sidebar in our functions.php file (if you don&#8217;t have a functions.php file, create one). At the simplest form this is</p>
<pre class="brush: php;">if ( function_exists('register_sidebar') ) {
    register_sidebar();
}</pre>
<p>This will set your widgets up in an unordered list with the widget title in a h2 and the content in an unordered list eg.</p>
<pre class="brush: html;">&lt;ul&gt;
    &lt;li&gt;&lt;h2&gt;Widget Title&lt;/h2&gt;
        &lt;ul&gt;
            &lt;li&gt;Widget Item here&lt;/li&gt;
            &lt;li&gt;Another Item&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;h2&gt;Widget Title 2&lt;/h2&gt;
        &lt;ul&gt;
            &lt;li&gt;Widget Item here&lt;/li&gt;
            &lt;li&gt;Another Item&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Of course, this markup isn&#8217;t to everyone&#8217;s liking. Personally I prefer to use h3&#8217;s instead of h2 headings. So to do this we can override the default settings using the following code:</p>
<pre class="brush: php;">if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'before_widget' =&gt; '&lt;li&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;',
    ));
}</pre>
<p>If you want to be able to target the widget&#8217;s output even more then we can add an ID and class to the widget using the following code:</p>
<pre class="brush: php;">if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'before_widget' =&gt; '&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h3&gt;',
        'after_title' =&gt; '&lt;/h3&gt;',
    ));
}</pre>
<p>The ID is generated from the widget&#8217;s name and the class is generated from the widget&#8217;s callback.</p>
<p>So now we&#8217;ve got our sidebar set up in the functions file you can add widgets via the Appearance -> Widgets menu. Now we need to get them showing on the front end.</p>
<h3>The Sidebar</h3>
<p>The code required for the sidebar is a simple if statement that checks if we&#8217;ve registered a sidebar. If we have then it will show that, otherwise it will display what&#8217;s within the if statement. This is achieved using the following code:</p>
<pre class="brush: php;">if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) :</pre>
<p>This simply says &#8216;if the function dynamic_sidebar() doesn&#8217;t exist, or there&#8217;s no output from the function dynamic_sidebar() display the following&#8217;. Within the if statement you place the code that you want to display if the user doesn&#8217;t add any widgets to their sidebar (even if you&#8217;ve got the functions file and sidebar set up, if no widgets are added then no output is made and so the if condition becomes true and the code within it will display.</p>
<p>So this gives us the final code of</p>
<pre class="brush: php;">if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) :
    // enter HTML code here for items such as list categories, pages, recent posts etc.
endif;</pre>
<h3>Conclusion</h3>
<p>This is a simple addition but with widgets becoming quite popular, it&#8217;s a good idea to add the code in to make your theme even more flexible.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/">Widgetise Your Theme</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=7031&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/05/07/widgetise-your-theme/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Creating Theme Options</title>
		<link>http://www.bloggingtips.com/2009/04/30/creating-theme-options/</link>
		<comments>http://www.bloggingtips.com/2009/04/30/creating-theme-options/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:00:19 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=6854</guid>
		<description><![CDATA[If you create WordPress themes then a useful addition to a standard theme is to give the user a simple way to change the logo or header in use, perhaps allow them to change the colour of the background, the width of the site too. These options are designed to save people time but more [...]<p><a href="http://www.bloggingtips.com/2009/04/30/creating-theme-options/">Creating Theme Options</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you create WordPress themes then a useful addition to a standard theme is to give the user a simple way to change the logo or header in use, perhaps allow them to change the colour of the background, the width of the site too. These options are designed to save people time but more importantly, to make it easy for non-developers to make a few alterations to their theme without needing to go looking through the code.</p>
<p>So first we need to create an admin page to go into the Appearance menu. To do this we can insert the page into the theme&#8217;s functions.php file. We create the page similar to how we <a href="http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/">created admin pages for our plugin</a>. e.g.</p>
<pre class="brush: php;">add_action('admin_menu', 'ourtheme_add_theme_pg');

function ourtheme_add_theme_pg() {
    add_theme_page(__('Theme Options'), __('Theme Options'), 'edit_themes', basename(__FILE__), 'ourtheme_functions');
}</pre>
<p>This will add a new menu item called Theme Options into our Appearance menu in the admin. Then we need to decide what options we&#8217;re going to offer the users. Bear in mind, the more options you offer, the more code is required and the slower the site can become. I&#8217;ve seen a site slow down from 0.5 seconds to 15 seconds load time, just due to a badly written theme options page!</p>
<p>So let&#8217;s allow the user to change the image file used. In the theme directory you can create an images directory to store a number of different banners (or the user can add more of their own), so we&#8217;ll just give them the option of choosing one of these rather than going through the code of how to upload an image to the website.</p>
<h3>The Basic Admin Page</h3>
<p>Let&#8217;s just grab the basic admin page code again to use as our template:</p>
<pre class="brush: html;">&lt;div class=&quot;wrap&quot;&gt;
 	&lt;form id=&quot;options_form&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;h2&gt;&lt; ?php _e('Theme Options'); ?&gt;&lt;/h2&gt; 

		&lt;div class=&quot;ui-sortable&quot;&gt;
			&lt;div class=&quot;postbox&quot;&gt;
				&lt;h3 class=&quot;hndle&quot;&gt;&lt; ?php _e('Sub Header'); ?&gt;&lt;/h3&gt;
				&lt;div class=&quot;inside&quot;&gt;

					** Form or content goes here **

				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;</pre>
<h3>List Banners Available</h3>
<p>On the page we&#8217;ll check all of the banners available within the images directory and list them in a select list. We&#8217;ll also pre-select the current one used:</p>
<pre class="brush: php;">&lt;div&gt;&lt;label for=&quot;topimg&quot;&gt;Top Banner&lt;/label&gt;
&lt;select id=&quot;topimg&quot; name=&quot;topimg&quot;&gt;
&lt; ?php
$template_dir = get_template_directory();
$default_file = &quot;header.gif&quot;;
$allowed_file_ext = array(&quot;.gif&quot;, &quot;.png&quot;, &quot;.jpg&quot;, &quot;jpeg&quot;);

if (get_option(&quot;ourtheme_header&quot;)) $default_file = get_option(&quot;ourtheme_header&quot;);

if ($handle = opendir($template_dir.'/images/')) {
    while (false !== ($file = readdir($handle))) {
        if (in_array(substr($file, -4), $allowed_file_ext) {
            echo &quot;&lt;option value='&quot;.$file.&quot;'&quot;.($file == $default_file ? ' selected=&quot;selected&quot;' : '').&quot;&gt;&quot;.$file.&quot;\n&quot;;
        }
    }
    closedir($handle);
}
?&gt;
&lt;/select&gt;&lt;/div&gt;</pre>
<p>Here we open up the images directory within the template directory (found by using the WordPress function <a href="http://codex.wordpress.org/Function_Reference/get_template_directory">get_template_directory()</a>) and then loop through each file found and add it to our select list providing it is an image file (achieved by checking the last 4 characters of each file found against the array of file extensions). This also checks the filename against the current file in use and marks the option as selected if it matches.</p>
<p>This code, along with a submit button is then inserted into our default admin page code above.</p>
<h3>Process the Form</h3>
<p>To process the form all we need to do is check the submit button has been clicked, if it has then grab the image selected and store it in our options table i.e.</p>
<pre class="brush: php;">if (isset($_POST['theme_submit'])) :
    update_option('ourtheme_header', $_POST['topimg']);
    echo '&lt;div id=&quot;message&quot; class=&quot;updated fade&quot;&gt;&lt;p&gt;&lt;strong&gt;'.__('Options saved.').'&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;';
endif;</pre>
<h3>Final Admin Code</h3>
<p>This gives us the final code to go into our functions file of:</p>
<pre class="brush: php;">add_action('admin_menu', 'ourtheme_add_theme_pg');

function ourtheme_add_theme_pg() {
    add_theme_page(__('Theme Options'), __('Theme Options'), 'edit_themes', basename(__FILE__), 'ourtheme_functions');
}

function ourtheme_functions() {
    if (isset($_POST['theme_submit'])) :
        update_option('ourtheme_header', $_POST['topimg']);
        echo '&lt;div id=&quot;message&quot; class=&quot;updated fade&quot;&gt;&lt;p&gt;&lt;strong&gt;'.__('Options saved.').'&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;';
    endif;
?&gt;

&lt;div class=&quot;wrap&quot;&gt;
 	&lt;form id=&quot;options_form&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;h2&gt;&lt; ?php _e('Theme Options'); ?&gt;&lt;/h2&gt; 

		&lt;div class=&quot;ui-sortable&quot;&gt;
			&lt;div class=&quot;postbox&quot;&gt;
				&lt;h3 class=&quot;hndle&quot;&gt;&lt; ?php _e('Sub Header'); ?&gt;&lt;/h3&gt;
				&lt;div class=&quot;inside&quot;&gt;

					&lt;div&gt;&lt;label for=&quot;topimg&quot;&gt;Top Banner&lt;/label&gt; &lt;select id=&quot;topimg&quot; name=&quot;topimg&quot;&gt;
						&lt; ?php
						$template_dir = get_template_directory();
						$default_file = &quot;header.gif&quot;;
						$allowed_file_ext = array(&quot;.gif&quot;, &quot;.png&quot;, &quot;.jpg&quot;, &quot;jpeg&quot;);

						if (get_option(&quot;ourtheme_header&quot;)) $default_file = get_option(&quot;ourtheme_header&quot;);

						if ($handle = opendir($template_dir.'/images/')) {
						    while (false !== ($file = readdir($handle))) {
						        if (in_array(substr($file, -4), $allowed_file_ext)) {
						            echo &quot;&lt;option value='&quot;.$file.&quot;'&quot;.($file == $default_file ? ' selected=&quot;selected&quot;' : '').&quot;&gt;&quot;.$file.&quot;\n&quot;;
						        }
						    }
						    closedir($handle);
						}
						?&gt;
					&lt;/select&gt;&lt;/div&gt;

				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;

&lt; ?php } ?&gt;</pre>
<h3>Front End Edits</h3>
<p>Finally all we need to do is set up the code for the header.php file to check which banner to display. So wherever the banner is displayed we just need to take the default image filename out and use the following PHP code:</p>
<pre class="brush: php;">&lt;img src=&quot;&lt; ?php bloginfo('template_url');
$headerimg = &quot;header.gif&quot;;
if (get_option(&quot;ourtheme_header&quot;)) $headerimg = get_option(&quot;ourtheme_header&quot;);

echo &quot;/images/&quot;.$headerimg.&quot; /&gt;&quot; alt=&quot;Top Banner&quot; /&gt;</pre>
<p>Alternatively, if your banner is using the <a href="http://www.bloggingtips.com/2009/04/02/css-image-replacement/">image replacement technique</a>, then you&#8217;re best off adding an action to add the CSS style needed to the wp_head() function in your function.php theme file e.g.</p>
<pre class="brush: php;">add_action(&quot;wp_head&quot;, &quot;ourtheme_addheader&quot;);

function ourtheme_addheader() {
    if (get_option(&quot;ourtheme_header&quot;)) :
        echo '&lt;style type=&quot;text/css&quot;&gt;#header { background: url('.get_option(&quot;ourtheme_header&quot;).'); &lt;/style&gt;';
    endif;
}</pre>
<p>This will then insert the style to override the default styling set up in your CSS stylesheet.</p>
<p>This is just a simple example of creating an options page for your theme, but the logic is the same for virtually all the options you could want to offer. Just create the various form elements to allow the user to make their changes, and save the selections and information in the options table using unique option names.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/04/30/creating-theme-options/">Creating Theme Options</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=6854&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/04/30/creating-theme-options/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Plugin Administration Menus</title>
		<link>http://www.bloggingtips.com/2009/04/05/plugin-administration-menus/</link>
		<comments>http://www.bloggingtips.com/2009/04/05/plugin-administration-menus/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 14:00:13 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=6210</guid>
		<description><![CDATA[When creating your own plugins you&#8217;ll often want to add one or more admin pages to allow users to configure options and add content, depending on what your plugin does. A couple of weeks ago I explained how to add an Options Page, this week I&#8217;ll run through how to add pages to other sections.
Creating [...]<p><a href="http://www.bloggingtips.com/2009/04/05/plugin-administration-menus/">Plugin Administration Menus</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>When creating your own plugins you&#8217;ll often want to add one or more admin pages to allow users to configure options and add content, depending on what your plugin does. A couple of weeks ago I explained how to add an <a href="/2009/03/22/creating-a-wordpress-plugin-ii/">Options Page</a>, this week I&#8217;ll run through how to add pages to other sections.</p>
<h3>Creating a Submenu Page</h3>
<p>The syntax of using these predefined functions is the same as using the options page function. To remind ourselves, this is</p>
<pre class="brush: php;">add_options_page(Page Title, Menu Title, user level / capability, file, function name, icon url);</pre>
<p>For adding a management page, which will then appear under the Tools menu (for WordPress 2.6 and below this would appear on the management menu), we use</p>
<pre class="brush: php;">add_management_page(Page Title, Menu Title, user level / capability, file, function name, icon url);</pre>
<p>and for adding a page to the Theme management section we use</p>
<pre class="brush: php;">add_theme_page(Page Title, Menu Title, user level / capability, file, function name, icon url);</pre>
<p>If you want to add a menu page to another section then we use the standard add_submenu_page() function. This is almost the same as the predefined functions except we tell the function which admin page to make this a submenu of. The syntax for this function is</p>
<pre class="brush: php;">add_submenu_page(Parent File, Page Title, Menu Title, user level / capability, file, function name, icon url);</pre>
<p>The parent file is just the PHP filename (including the .php extension) of the parent file, all of which are listed below:</p>
<ul>
<li>For the Dashboard menu use index.php</li>
<li>For the Posts menu use edit.php</li>
<li>For the Media menu use media.php</li>
<li>For the Links menu use link-manager.php</li>
<li>For the Pages menu use edit-pages.php</li>
<li>For the Comments menu use edit-comments.php</li>
<li>For the Plugins menu use plugins.php</li>
<li>For the Users menu use users.php</li>
</ul>
<p>Of course the Appearance, Tools and Settings menus can be targeted using the predefined functions above.</p>
<h3>Creating a new Menu</h3>
<p>If you start to develop larger plugin files then you may find that you need several pages for users to manage their content. Once you get to this point then you&#8217;ll want to create a whole new menu section. To do this we use the add_menu_page() function, and then add subpages to that. The syntax to create your own menu is</p>
<pre class="brush: php;">add_menu_page(Page Title, Menu Title, User Level / Capability, file, function name, icon);
add_submenu_page(Parent File, 'Page Title', 'Menu Title', User Level / Capability, file, function name);</pre>
<p>Then you would repeat the submenu page function for each submenu page you need. For example, a recent plugin that I&#8217;ve created for converting a gallery section over to work in WordPress (without having to change 1000+ records to use the built in WP Gallery!), used the menu of</p>
<pre class="brush: php;">add_menu_page('Gallery Management', 'Gallery Management', 8, __FILE__, 'album_mgt_add');
add_submenu_page(__FILE__, 'Add a Gallery', 'Add a Gallery', 8, __FILE__, 'album_mgt_add');
add_submenu_page(__FILE__, 'Edit a Gallery', 'Edit a Gallery', 8, 'album_mgt_edit', 'album_mgt_edit');
add_submenu_page(__FILE__, 'Remove a Gallery', 'Remove a Gallery', 8, 'album_mgt_rem', 'album_mgt_rem');</pre>
<p>In the add_menu_page() the fourth parameter is told to use the existing plugin file to find the album_mgt_add() function. Then in the first submenu page I&#8217;ve used similar parameters (except the additional first parameter is set to use the plugin file as the parent, so that the submenu page appears in the correct menu), so that if you click on the &#8216;Gallery Management&#8217; main menu heading, or open it up and click on the Add a Gallery, both will go to the Add a Gallery page, similar to how the other admin menus work. For the Edit and Remove pages I&#8217;ve set the fifth and sixth parameters to use the function name as all the functions are in one file. If you were to split the plugin into several files (recommended for very large plugins) then you would set the fifth parameter to be the filename of where WordPress can find the function.</p>
<h3>Controlling Access</h3>
<p>I personally prefer to use the user level system to control who can see the menus, which means that I tend to set a level access of 8 for Administrators only, 7 for Editors and Administrators, 2 for authors and then 0 for any registered user. You can read more about the roles and capabilities available to you from the <a href="http://codex.wordpress.org/Roles_and_Capabilities">WordPress Codex</a>.</p>
<p>Don&#8217;t forget, using a plugin that allows you to alter the default user roles and capabilities will also affect your plugin(s) so if you use this then be certain to check on your plugin access for the user types.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/04/05/plugin-administration-menus/">Plugin Administration Menus</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=6210&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/04/05/plugin-administration-menus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Plugin III</title>
		<link>http://www.bloggingtips.com/2009/03/29/creating-a-wordpress-plugin-iii/</link>
		<comments>http://www.bloggingtips.com/2009/03/29/creating-a-wordpress-plugin-iii/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 15:00:17 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=6050</guid>
		<description><![CDATA[This is the final part on the subject of creating a WordPress plugin (read part 1 and part 2). We&#8217;ll be modifying our original function, that outputs social bookmark links after each post, so that it works with our new options page.
So first we need to modify our display function. At present it just echos [...]<p><a href="http://www.bloggingtips.com/2009/03/29/creating-a-wordpress-plugin-iii/">Creating a WordPress Plugin III</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is the final part on the subject of creating a WordPress plugin (read <a href="http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/">part 1</a> and <a href="http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/">part 2</a>). We&#8217;ll be modifying our original function, that outputs social bookmark links after each post, so that it works with our new options page.</p>
<p>So first we need to modify our display function. At present it just echos out the markup, however we need it to do the following</p>
<ol>
<li>Put the markup into a variable</li>
<li>Check which option is set</li>
<li>If you should attach the links to the content, and the content isn&#8217;t empty, append the links variable created in point 1</li>
<li>Else, if the content is empty (therefore the function has been called directly), echo the links variable</li>
<li>Else, just return the original content without any links attached</li>
</ol>
<p>Okay so let&#8217;s look at this step by step.</p>
<h3>1. Put the markup in a variable</h3>
<p>Before we were just echoing the markup, now it needs to go into a variable. This also means we need to alter our template tags for the permalink and post title, as the ones in use before would echo the content out, but we want to just return it so that it&#8217;s in the variable. So to do this we can use</p>
<pre class="brush: php;">	$sblinks = '&lt;ul id=&quot;social&quot;&gt;
&lt;li&gt;Bookmark this page at: &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://del.icio.us/post?url='.get_permalink($post-&gt;ID).'&amp;amp;title='.urlencode($post-&gt;post_title).'&quot; title=&quot;Bookmark '.$post-&gt;post_title.' on Del.icio.us&quot;&gt;Del.icio.us&lt;/a&gt; - &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.stumbleupon.com/submit?url='.get_permalink($post-&gt;ID).'&amp;amp;title='.urlencode($post-&gt;post_title).'&quot; title=&quot;Submit '.$post-&gt;post_title.' to StumbleUpon&quot;&gt;StumbleUpon&lt;/a&gt; - &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.spurl.net/spurl.php?url='.get_permalink($post-&gt;ID).'&amp;amp;title='.urlencode($post-&gt;post_title).'&quot; title=&quot;Bookmark '.$post-&gt;post_title.' on Spurl&quot;&gt;Spurl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;';</pre>
<h3>2. Check the option set</h3>
<p>This is fairly straightforward. We just need to get the value of the option set by the options page</p>
<pre class="brush: php;">$attach = get_option('sboption');</pre>
<h3>3. Check on attachment and content, append links</h3>
<p>This is where our if statement starts. We need to check that<br />
a: We have some content passed through the action hook to the function<br />
b: We have a setting to append the links to the content</p>
<pre class="brush: php;">if ($attach &amp;&amp; !empt y($content)) :
	$content .= $sblinks;
	return $content;</pre>
<h3>4. Else if the content is empty</h3>
<p>This is triggered if someone calls the function directly, as they won&#8217;t be passing content through to the function as a parameter, so we can just echo the links variable out instead.</p>
<pre class="brush: php;">elseif (empt y($content)) :
	echo $sblinks;
	return TRUE;</pre>
<h3>5. Else just return original content</h3>
<p>Finally, if there is content but the option to append links is not set, then just return the content untouched.</p>
<pre class="brush: php;">else :
	return $content;
endif;</pre>
<h3>The action hook</h3>
<p>Finally, we just need to add the action hook to get the function to run when ever post content is displayed using the_content() tag as the hook. We do this using</p>
<pre class="brush: php;">add_filter('the_content', 'display_sblinks');</pre>
<h3>The Final Code</h3>
<p>So that gives us our final code for the full plugin which you can view/copy at <a href='http://www.bloggingtips.com/wp-content/uploads/2009/03/sblinks1.txt'>Social Bookmark Links</a>.</p>
<p>This file can just be added to your plugins directory and activated in your admin.</p>
<p>To target the list of links I recommend the following CSS:</p>
<pre class="brush: css;">ul.socialbm { margin-left: 0; padding-left: 0; }
ul.socialbm li {
	list-style-type: none;
	float: left;
	width: auto;
	margin-right: 5px;
}</pre>
<h3>Plugin Enhancements</h3>
<p>This is only a very simple plugin with just one option. You could extend this by allowing the user to select which links / networking sites to display, whether to append the links to posts only or pages as well. You could add a class to each list item to allow you to insert the social bookmark icon next to each link. The plugin is very extendable and should allow you to experiment further with the code already there.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/03/29/creating-a-wordpress-plugin-iii/">Creating a WordPress Plugin III</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=6050&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/03/29/creating-a-wordpress-plugin-iii/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Plugin II</title>
		<link>http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/</link>
		<comments>http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 15:00:16 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=5936</guid>
		<description><![CDATA[Last week I explained how to take a function and turn it into a plugin for your WordPress site. The plugin was fairly basic, just a function that created a list of social bookmarks. To use it you would just make a call to the function within your template file. However, we can go one [...]<p><a href="http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/">Creating a WordPress Plugin II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Last week I explained how to <a href="http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/">take a function and turn it into a plugin</a> for your WordPress site. The plugin was fairly basic, just a function that created a list of social bookmarks. To use it you would just make a call to the function within your template file. However, we can go one better and give the user an option of either controlling where the bookmarks are displayed (as it currently is), or for those less confident in editing their template files, we can give them the option to choose to simply have the bookmarks added to the bottom of their post.</p>
<p>So to do this, first we need to create an options page. To add an options page we need to use an action which calls a function to add the page to the options menu, plus it tells that menu option which function to run for the options page (with me so far?!). So step 1, call the action</p>
<pre class="brush: php;">add_action('admin_menu', 'add_options_pg');</pre>
<p>Second step is to create the function &#8216;add_options_pg&#8217; which adds the menu option:</p>
<pre class="brush: php;">function add_options_pg() {
    add_options_page(Page Title, Menu Title, user level / capability, file, function name, icon url);
}</pre>
<p>The above function takes the given parameters to create the menu label. For our plugin we could use</p>
<pre class="brush: php;">function add_options_pg() {
    add_options_page('Add Social Bookmarks', 'Social Bookmarks', 8, basename(__FILE__), 'sblinks_options');
}</pre>
<p>You may noticed that I&#8217;ve omitted the last parameter. It&#8217;s not essential unless you want to give your plugin a menu icon that appears to the left of the label in the menu. The fourth parameter tells the function that the options page function is in the same file.</p>
<p>So now we&#8217;ve got the menu label and on clicking it, it will run the function sblinks_options(), so we need to set our page up within that. For a function page you need your processing script and then the page/form below it, wrapped within the same function. So for our page for our plugin we just need to give the option of whether to attach the output to the bottom of every page and post or not.</p>
<p>For our HTML we can use:</p>
<pre class="brush: html;">&lt;div class=&quot;wrap&quot;&gt;
 	&lt;form id=&quot;options_form&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;h2&gt;Manage Social Bookmarks&lt;/h2&gt; 

		&lt;div class=&quot;ui-sortable&quot;&gt;
			&lt;div class=&quot;postbox&quot;&gt;
				&lt;h3 class=&quot;hndle&quot;&gt;Social Bookmark Options&lt;/h3&gt;
				&lt;div class=&quot;inside&quot;&gt;

					&lt;div&gt;&lt;label for=&quot;sboption&quot;&gt;Display after Page/Post?&lt;/label&gt;
					&lt;input type=&quot;checkbox&quot; id=&quot;sboption&quot; name=&quot;sboption&quot; value=&quot;1&quot; /&gt;
					&lt;/div&gt;
					&lt;div class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;sb_submit&quot; id=&quot;sb_submit&quot; value=&quot;Update Options&quot; /&gt;&lt;/div&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;</pre>
<p>This outputs a simple form with a checkbox. The markup and classes used for the divs are already used in the WordPress admin so this will keep the page in the same design.</p>
<p>Now we need the code to process this form. As this is an option then we save it in the options table within the WordPress database. To do this we use the function update_option, ie.</p>
<pre class="brush: php;">if (isset($_POST['sb_submit'])):
	update_option('sboption', $_POST['sboption']);

	echo '&lt;div id=&quot;message&quot; class=&quot;updated fade&quot;&gt;&lt;p&gt;Option Saved!&lt;/p&gt;&lt;/div&gt;';
endif;</pre>
<p>Here we&#8217;ve checked to see if the form has been submitted. Then we use the update_option to update the option value &#8217;sboption&#8217; with the value of the checkbox (0 for unchecked, 1 for checked). With the update_option() function, it checks to see if the option specified exists. If it doesn&#8217;t then it will add the option, if it does exist it will update the existing one, so it does two jobs in one. Once we&#8217;ve updated the option we can echo out the message that the selection has been saved. Again, the markup used fits in with WordPress&#8217;s own markup and will allow the message to fade in as it does on other pages.</p>
<p>So now we&#8217;ve got the form and the form processing script. Finally we need to check what the option currently is in the options table, so that the checkbox can reflect that. To do this we use the get_option() function to get the value of the option, ie.</p>
<pre class="brush: php;">if (get_option('sboption')) {
	$sboption = ' checked=&quot;checked&quot;';
} else {
    $sboption = '';
}</pre>
<p>As we&#8217;ve stored the option value as 0 or 1 then we can use a simple if statement to check the value of it. 0 will also give a false value, so if the value is 1 (ie. true) then our variable $sboption gets an additional piece of HTML markup to add to the form, making our checkbox checked. If the value is false then it&#8217;s just set to be empty. We can then insert this into our input code:</p>
<pre class="brush: html;">&lt;input type=&quot;checkbox&quot; id=&quot;sboption&quot; name=&quot;sboption&quot; value=&quot;1&quot;&lt; ?php echo $sboption ?/&gt; /&gt;</pre>
<p>This will then set the checkbox as checked if the option has been selected previously.</p>
<p>This now gives us the final code as:</p>
<pre class="brush: php;">&lt; ?php
add_action('admin_menu', 'add_options_pg');

function add_options_pg() {
    add_options_page('Add Social Bookmarks', 'Social Bookmarks', 8, basename(__FILE__), 'sblinks_options');
}

function sblinks_options() {
    if (isset($_POST['sb_submit'])):
	update_option('sboption', $_POST['sboption']);

	echo '&lt;div id=&quot;message&quot; class=&quot;updated fade&quot;&gt;&lt;p&gt;Option Saved!&lt;/p&gt;';
    endif;

    if (get_option('sboption')) {
	$sboption = ' checked=&quot;checked&quot;';
    } else {
        $sboption = '';
    }
?&gt;

&lt;div class=&quot;wrap&quot;&gt;
 	&lt;form id=&quot;options_form&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;h2&gt;Manage Social Bookmarks&lt;/h2&gt; 

		&lt;div class=&quot;ui-sortable&quot;&gt;
			&lt;div class=&quot;postbox&quot;&gt;
				&lt;h3 class=&quot;hndle&quot;&gt;Social Bookmark Options&lt;/h3&gt;
				&lt;div class=&quot;inside&quot;&gt;

   					&lt;div&gt;&lt;label for=&quot;sboption&quot;&gt;Display after Page/Post?&lt;/label&gt;
       					&lt;input type=&quot;checkbox&quot; id=&quot;sboption&quot; name=&quot;sboption&quot; value=&quot;1&quot; /&gt;
       					&lt;/div&gt;
					&lt;div class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;sb_submit&quot; id=&quot;sb_submit&quot; value=&quot;Update Options&quot; /&gt;&lt;/div&gt;
       				&lt;/div&gt;
       			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;

&lt; ?php } ?&gt;</pre>
<p>This can go into the plugin file that we created <a href="http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/">last week</a>.</p>
<p>Next week I&#8217;ll conclude this plugin to show you how to alter last weeks function to check on the option and output the social bookmark links accordingly.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/">Creating a WordPress Plugin II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=5936&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/03/22/creating-a-wordpress-plugin-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Plugin</title>
		<link>http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/</link>
		<comments>http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 15:00:36 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=5872</guid>
		<description><![CDATA[Over the past couple of months we&#8217;ve started to look at creating functions and using actions and filters in our functions.php theme file to help manipulate the content output by WordPress. If you create something and feel it&#8217;s worthy of releasing for others to use then rather than just posting the code up for others [...]<p><a href="http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/">Creating a WordPress Plugin</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Over the past couple of months we&#8217;ve started to look at creating functions and using actions and filters in our functions.php theme file to help manipulate the content output by WordPress. If you create something and feel it&#8217;s worthy of releasing for others to use then rather than just posting the code up for others to copy, it&#8217;s usually better to write a plugin.</p>
<p>To start a plugin file off you use a PHP comment to contain the information about the plugin. This is:</p>
<pre class="brush: php;">&lt; ?php
/*
Plugin Name: Put your plugin name here
Plugin URI: http://www.yourdomain.com/path-to-plugin-page/
Description: Plugin description here
Version: 1.0
Author: Your Name
Author URI: http://www.yourdomain.com
*/
?&gt;</pre>
<p>The above tells WordPress information about your plugin and this is the information that gets displayed on the plugins page in the admin section.</p>
<p>After this you can then add your functions and hooks/filters if needed. If we take the simple function we first looked at, <a href="http://www.bloggingtips.com/2009/01/04/using-a-functions-file/">to output social bookmarking links</a>, then we would simply add the function below the comments eg.</p>
<p><code>&lt;?php<br />
/*<br />
Plugin Name: Output Social Bookmarks<br />
Plugin URI: http://www.bloggingtips.com/wordpress-plugins/social-bookmarks/<br />
Description: Displays Social Bookmarks for the current post.<br />
Version: 1.0<br />
Author: SarahG<br />
Author URI: http://www.bloggingtips.com<br />
*/<br />
function display_sblinks($cssid = &quot;social&quot;) {<br />
	global $post;<br />
?&gt;<br />
	&lt;ul id=&quot;&lt;?php echo $cssid ?&gt;&quot;&gt;<br />
		&lt;li&gt;Bookmark this page at: &lt;/li&gt;<br />
		&lt;li&gt;&lt;a href=&quot;http://del.icio.us/post?url=&lt;?php the_permalink() ?&gt;&amp;amp;title=&lt;?php echo urlencode(the_title('','',FALSE)); ?&gt;&quot; title=&quot;Bookmark &lt;?php the_title() ?&gt; on Del.icio.us&quot;&gt;Del.icio.us&lt;/a&gt; - &lt;/li&gt;<br />
		&lt;li&gt;&lt;a href=&quot;http://www.stumbleupon.com/submit?url=&lt;?php the_permalink() ?&gt;&amp;amp;title=&lt;?php echo urlencode(the_title('','',FALSE)); ?&gt;&quot; title=&quot;Submit &lt;?php the_title() ?&gt; to StumbleUpon&quot;&gt;StumbleUpon&lt;/a&gt; - &lt;/li&gt;<br />
		&lt;li&gt;&lt;a href=&quot;http://www.spurl.net/spurl.php?url=&lt;?php the_permalink() ?&gt;&amp;amp;title=&lt;?php echo urlencode(the_title('','',FALSE)); ?&gt;&quot; title=&quot;Bookmark &lt;?php the_title() ?&gt; on Spurl&quot;&gt;Spurl&lt;/a&gt;&lt;/li&gt;<br />
     	&lt;/ul&gt;<br />
&lt;?php<br />
}<br />
?&gt;</code></p>
<p>You would save this as a standard PHP file and then put it in your plugins directory. When you then go into the plugins page you&#8217;ll see it as an unactivated plugin ie. just like any other plugin you&#8217;ve added to your site.</p>
<p>Next week I&#8217;ll explain how to give more flexibility and control over your plugins with an options page.</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/">Creating a WordPress Plugin</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=5872&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/03/15/creating-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Create a Breadcrumb Trail II</title>
		<link>http://www.bloggingtips.com/2009/03/01/create-a-breadcrumb-trail-ii/</link>
		<comments>http://www.bloggingtips.com/2009/03/01/create-a-breadcrumb-trail-ii/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 15:00:00 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[WordPress Coding & Design]]></category>

		<guid isPermaLink="false">http://www.bloggingtips.com/?p=5730</guid>
		<description><![CDATA[Last week I wrote about creating a breadcrumb trail, explaining how to do this for your front page, static Page and single post page. This leaves us with the category page and archives (day, month and year).
Category Page
The category page is quite similar to the single post page code that we saw last week, except [...]<p><a href="http://www.bloggingtips.com/2009/03/01/create-a-breadcrumb-trail-ii/">Create a Breadcrumb Trail II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote about <a href="http://www.bloggingtips.com/2009/02/22/create-a-breadcrumb-trail/">creating a breadcrumb trail</a>, explaining how to do this for your front page, static Page and single post page. This leaves us with the category page and archives (day, month and year).</p>
<h3>Category Page</h3>
<p>The category page is quite similar to the single post page code that we saw last week, except that we use the single_cat_title() function along with the get_cat_id function to get the category ID of the page we&#8217;re on (get_the_category() wouldn&#8217;t work for category pages, as it&#8217;ll pick up all categories for the first post on the page and can potentially mess things up!) ie.</p>
<pre class="brush: php;">if (is_category()) :
	$pdata = get_cat_id( single_cat_title(&quot;&quot;,false) );
	$data = get_category_parents($pdata, TRUE, ' &amp;raquo; ');

	$trail .= &quot; &amp;raquo; &quot;.substr($data,0,-9);
endif;</pre>
<h2>The Archives</h2>
<p>The archive pages can be for a day, month or year, so we need to cover all 3 potential options. Note, to reduce a database call I&#8217;ve used paths relative to the root so you may need to edit these if your WordPress install is within a directory.</p>
<h3>Day Archives</h3>
<p>For the Day archives we want it in the format of Year &raquo; Month &raquo; Day, with the year and month being linked. To do this we can use the following code:</p>
<pre class="brush: php;">if (is_day()) :
	$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y').&quot;/'&gt;&quot;.get_the_time('Y').&quot;&lt;/a&gt;&quot;;
	$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y/m').&quot;/'&gt;&quot;.get_the_time('F').&quot;&lt;/a&gt;&quot;;
	$trail .= &quot; &amp;raquo; &quot;.get_the_time('l');
endif;</pre>
<p>Here we check if the archive page is a daily archive page, if so then we use the tag <a href="http://codex.wordpress.org/Template_Tags/get_the_time">get_the_time()</a> to get the information about the archives. This tag accepts the various <a href="http://www.php.net/date">PHP Date</a> formatting to determine what to display. Here I&#8217;ve used the Y to get the full 4 digit year eg. 2009, then for the month archive link I&#8217;ve used Y/m which would insert 2009/02 into our link. I&#8217;ve set the month anchor text however to use &#8216;F&#8217; which will display the name in full.</p>
<p>Finally I&#8217;ve then set the day to display as its name in full, using the &#8216;l&#8217; (lowercase L). This isn&#8217;t linked as you&#8217;re already on the page for this <img src='http://www.bloggingtips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  This will then give an output such as</p>
<p><a href="">Home</a> &raquo; <a href="">2009</a> &raquo; <a href="">February</a> &raquo; Sunday</p>
<h3>Month and Year Archives</h3>
<p>For the Month and Year Archives we just adapt the above code for the day, slowly removing the additional &#8216;crumb&#8217; at the end of the output, so for these two archives we use</p>
<pre class="brush: php;">if (is_month()) :
	$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y').&quot;/'&gt;&quot;.get_the_time('Y').&quot;&lt;/a&gt;&quot;;
	$trail .= &quot; &amp;raquo; &quot;.get_the_time('F');
elseif (is_year()) :
	$trail .= &quot; &amp;raquo; &quot;.get_the_time('Y');
endif;</pre>
<h3>Final Code</h3>
<p>So our final function code, including the code from last week, should now be:</p>
<pre class="brush: php;">function write_breadcrumb() {
	$pid = $post-&gt;ID;
	$trail = &quot;&lt;a href='/'&gt;Home&lt;/a&gt;&quot;;

	if (is_front_page()) :
		// do nothing
	elseif (is_page()) :
		$bcarray = array();
		$pdata = get_post($pid);
		$bcarray[] = &quot; &amp;raquo; &quot;.$pdata-&gt;post_title.&quot;\n&quot;;
		while ($pdata-&gt;post_parent) :
			$pdata = get_post($pdata-&gt;post_parent);
			$bcarray[] = &quot; &amp;raquo; &lt;a href='&quot;.get_permalink($pdata-&gt;ID).&quot;'&gt;&quot;.$pdata-&gt;post_title.&quot;&lt;/a&gt;\n&quot;;
		endwhile;
		$bcarray = array_reverse($bcarray);
		foreach ($bcarray AS $listitem) :
			$trail .= $listitem;
		endforeach;
	elseif (is_single()) :
		$pdata = get_the_category($pid);
		$data = get_category_parents($pdata[0]-&gt;cat_ID, TRUE, ' &amp;raquo; ');

		$trail .= &quot; &amp;raquo; &quot;.substr($data,0,-8);
	elseif (is_category()) :
		$pdata = get_cat_id( single_cat_title(&quot;&quot;,false) );
		$data = get_category_parents($pdata, TRUE, ' &amp;raquo; ');

		$trail .= &quot; &amp;raquo; &quot;.substr($data,0,-9);
	elseif (is_day()) :
		$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y').&quot;/'&gt;&quot;.get_the_time('Y').&quot;&lt;/a&gt;&quot;;
		$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y/m').&quot;/'&gt;&quot;.get_the_time('F').&quot;&lt;/a&gt;&quot;;
		$trail .= &quot; &amp;raquo; &quot;.get_the_time('l');
	elseif (is_month()) :
		$trail .= &quot; &amp;raquo; &lt;a href='/&quot;.get_the_time('Y').&quot;/'&gt;&quot;.get_the_time('Y').&quot;&lt;/a&gt;&quot;;
		$trail .= &quot; &amp;raquo; &quot;.get_the_time('F');
	elseif (is_year()) :
		$trail .= &quot; &amp;raquo; &quot;.get_the_time('Y');
	endif;

	return $trail;
}
</pre>
<p>The above code uses a right angled quote to separate the links however the most suitable markup for this is to use a list (except WordPress didn&#8217;t want me to paste that into the post!) so if you would rather use a list you can <a href='http://www.bloggingtips.com/wp-content/uploads/2009/03/breadcrumb-function.zip'>download the complete function</a>, and just insert it into your functions.php file.</p>
<h3>Remaining Pages</h3>
<p>You may think, what about the other pages &#8211; tags, author pages and search results. I&#8217;ve not done this as the only page &#8216;above&#8217; them is the home page, however if you wanted to add them in then you could use the correct conditional for each and just extend the if else statement above. These conditionals are is_tag(), is_author() and is_search().</p>
<hr>Copyright &copy; 2010 <strong><a href="http://www.bloggingtips.com">Blogging Tips</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href=http://www.bloggingtips.com/contact/>contact us</a> so we can take legal action immediately.<p><a href="http://www.bloggingtips.com/2009/03/01/create-a-breadcrumb-trail-ii/">Create a Breadcrumb Trail II</a><br /><br />
<a href="http://www.bloggingtips.com/books/"><img src="http://www.bloggingtips.com/ebooks/images/blogging-tips-books.png" alt="Blogging Tips Books"></a><br />
A selection of e-books to help you improve as a blogger.
Find out more at <a href="http://www.bloggingtips.com/books">www.bloggingtips.com/books/</a></p>
<img src="http://www.bloggingtips.com/?ak_action=api_record_view&id=5730&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.bloggingtips.com/2009/03/01/create-a-breadcrumb-trail-ii/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
