<?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>Weblimner &#187; Plugin</title>
	<atom:link href="http://www.weblimner.com/tag/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weblimner.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Aug 2010 23:49:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Making of Q-List Plugin for Wordpres &#8211; 1 of 2</title>
		<link>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/</link>
		<comments>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 03:35:30 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[plugin naming]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wpdb]]></category>
		<category><![CDATA[wp_options]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=193</guid>
		<description><![CDATA[This is the first article of a series of articles explaining how I created the Q-List WordPress plugin. First article will explain the administration section and the second will explain the user interface. This article consists of the following steps: Versioning your plugins database tables, and updating them Creating your administration interface Using wp options [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first article of a series of articles explaining how I created the Q-List WordPress plugin. First article will explain the administration section and the second will explain the user interface. This article consists of the following steps:</p>
<ul>
<li>Versioning your plugins database tables, and updating them</li>
<li>Creating your administration interface</li>
<li>Using wp options table in your database for your plugin options</li>
</ul>
<p><span id="more-193"></span><br />
First we are going to start with the naming of our plugin. This step is really important if you want your plugin to work correctly. You need to name the folder same as your plugin’s file name. In our example we are going to name our plugin file q-list-list-creator.php and store it in q-list-list-creator. So our file structure is;<br/><br />
<img src="http://www.weblimner.com/wp-content/uploads/2010/2/filestructure.gif" alt="File" /><br/><br />
After you place the file under the right place, now it’s time for our comment section. If you don’t put this into your plugin, WordPress won’t know your file is a plugin. The following is the way I kept my plugins comment section, it&#8217;s pretty simple and yet keeps track of updates. For the full list of comments section, you can check <a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">here</a>.<br/></p>
<pre class="php">/*
Plugin Name: Q-List
Plugin URI: http://www.weblimner.com/plugin/q-lists-list-creator/
Description: Create a list on your website and let members to vote the items of the list.
Author: Ali Sipahioglu
Author URI: http://www.weblimner.com
Version: 1.0
Change Log:
2010-30-01  1.0: In this version, users can vote without being a member of your website. Cookies are used. Design is changed. Percentages are shown for the results.
2010-20-01  0.6: Ability to see the results of the votes
2010-08-01  0.5: First release
*/</pre>
<p>The way the change log works is; you put your date first and then the version number and then briefly describe the updates you made. This is actually a good habit for when you go back to your code in the future, keeping track of an update and what it was.<br />
<br/><br />
<span class="important">Don&#8217;t forget to cover your whole file&#8217;s content with  tags.</span><br />
<br/><br />
At this point, WordPress will know the presence of your plugin, you will see it if you go to the wp-admin &gt; plugins.<br />
<br/><br />
Now we need to create the link to your plugin in your Settings menu. For that, create an action to hook your function to your admin menu. To do so;<br />
<br/></p>
<pre class="php">add_action('admin_menu', 'qlist_menu');</pre>
<p>qlist_menu is the function name that is going to create the menu item in your admin menu, so let&#8217;s create our qlist_menu function.</p>
<pre class="php">function qlist_menu(){
     add_options_page('Q-List Options', 'Q-List Options', 'administrator', 'qlist_unique', 'qlist_options');
}
</pre>
<p><br/><br />
Options are as follows;</p>
<ol>
<li>Title of your plugin in the administration.</li>
<li>Link that appears in the settings menu.</li>
<li>Capability required to see the menu link. In our case, you need to have administrator privileges to see it. You also have editor, author, contributor, subscriber options.</li>
<li>This has to be a unique name different from any plugin you might install to your WordPress installation so its better to keep your plugin name before it and then just but a string at the end like I did.</li>
<li>Name of the function that&#8217;s going to handle the administration view.</li>
</ol>
<p><br/>Now its time for your function.<br/></p>
<pre class="php">function qlist_options(){

}</pre>
<p><br/><br />
In our function we are going to use database calls so we need the database class of WordPress (<a href="http://codex.wordpress.org/Function_Reference/wpdb_Class" target="_blank">wpdb</a>). So lets add the following code to the first line of your function.</p>
<pre class="php">global $wpdb;</pre>
<p><br/>First we are going to create our form on the page.</p>
<pre class="php">$i=0;
echo '&lt;div class="wrap"&gt;
	 &lt;h2&gt;Q-List &lt;b&gt;Add New&lt;/b&gt;&lt;/h2&gt;
		 &lt;form method="post" action=""&gt;
		 &lt;table&gt;
			 &lt;tr&gt;
				&lt;th scope="row"&gt;Question&lt;/th&gt;
				&lt;td&gt;&lt;input type="text" name="question'.$i.'" size="60" /&gt;&lt;/td&gt;
				&lt;td&gt;Order: &lt;input type="text" name="order'.$i.'" size="5"/&gt;&lt;/td&gt;
			 &lt;/tr&gt;
			 &lt;tr&gt;
				 &lt;td colspan="3" align="center"&gt;
					 &lt;input type="hidden" name="addnewform" value="1"/&gt;
					 &lt;input type="submit" value="Save" /&gt;
				 &lt;/td&gt;
			 &lt;/tr&gt;
 ';
 echo     '&lt;/table&gt;&lt;/form&gt;';
 echo '&lt;h2&gt;Q-List &lt;b&gt;Edit&lt;/b&gt;&lt;/h2&gt;

 ';
 $db_questions = $wpdb-&gt;get_results("SELECT * from ".$wpdb-&gt;prefix."qlists order by q_order,question");
 foreach ($db_questions as $db_question) {$i++;
 echo
 '
 &lt;form method="post" action=""&gt;
	 &lt;table&gt;
		 &lt;tr&gt;
		 &lt;th scope="row"&gt;Question #'.($i-1).'&lt;/th&gt;
			 &lt;td&gt;&lt;input type="text" name="question" size="60" value="'.$db_question-&gt;question.'"/&gt;&lt;/td&gt;
			 &lt;td&gt;
			 Order: &lt;input type="text" name="order" size="5" value="'.$db_question-&gt;q_order.'"/&gt;
			 &lt;input type="hidden" name="updateform" value="'.$db_question-&gt;q_id.'"/&gt;
			 &lt;input type="submit" value="Update" /&gt;
			 &lt;a href="options-general.php?page=qlist_unique&amp;amp;delete='.$db_question-&gt;q_id.'" onclick="return confirm(\'You sure you want to delete?\');"&gt;Delete&lt;/a&gt;
			 &lt;/td&gt;
		 &lt;/tr&gt;
	 &lt;/table&gt;
 &lt;/form&gt;
 ';
 }

 echo     '&lt;/div&gt;';</pre>
<p>First part of our code only shows the empty form for a new step an admin might want to add. We set our action to nothing so when we submit it just comes back to the same page and then we query our database to see if there are any steps are already in. In our query we have &#8220;$wpdb-&gt;prefix&#8221; which creates that &#8220;wp_&#8221; in most cases that you have set when you set up your WordPress. And then its a foreach statement that goes through our array of results and prints them onto the page.<br />
<br/><br />
At this point besides our database updates, deletes, and adds our administration screen is set. Now its time to handle our form submissions.<br/></p>
<pre class="php">if($_POST['addnewform']){
 // Assign all the questions to an array
 $f_q= $HTTP_POST_VARS;
 for($a=0;$a&lt;((count($f_q)/2)-1);$a++){
	$form_questions[$a]["question"]=$_POST["question".($a+1)];
	$form_questions[$a]["order"]=$_POST["order".($a+1)];
 }
 // Get them into the database
 for($a=0;$a&lt;count($form_questions);$a++){
	 $wpdb-&gt;insert($wpdb-&gt;prefix."qlists",array('question'=&gt;$form_questions[$a]["question"],'q_order'=&gt;$form_questions[$a]["order"]),array( '%s', '%d' ));
 }
 }
 if($_POST['updateform']&gt;0){
	 $wpdb-&gt;update($wpdb-&gt;prefix."qlists",array('question'=&gt;$_POST['question'],'q_order'=&gt;$_POST["order"]),array( 'q_id' =&gt; $_POST['updateform'] ),array( '%s', '%d' ),array( '%d' ));
 }
 if($_GET['delete']){
	$wpdb-&gt;query("DELETE FROM ".$wpdb-&gt;prefix."qlists WHERE q_id = '".$_GET['delete']."'");
 }</pre>
<p>First if statement checks if it was a add new form by checking a hidden field that was set to 1 in our form. In our if statement I run through the array of post elements and save them into a multi-dimensional array and then I insert them into the WordPress database with the insert function. I am not going to explain how to do for loops in this article since I assume anyone that is creating a plugin for WordPress should know that much PHP. Now our insert function first gets the table name which is qlists with the prefix just like the way I explained earlier. Secondly it gets the an array for where you are going to put what so in our case its question that gets the question, q_order gets the order. And our last variable that we send in is an array that explains what type of data we are sending to each column in the database. &#8220;questions&#8221; is a string field so its %s and q_order is an integer field so its getting %d.  You can read more on this on the <a href="http://codex.wordpress.org/Function_Reference/wpdb_Class" target="_blank">wpdb</a> class page.<br />
<br/><br />
Next up is our update function. We update each step by itself, no loop going on here. All we do is check if it is an update form and if it is we update the database record. Only difference in this function is we need to tell what were going to update. In our case its determined by q_id that we got from the form and its an integer so we&#8217;ve set it at the end with %d.<br />
<br/><br />
That being said our administration section is done.<br />
<br/><br />
Now its time for our activation hook so that when someone activates/upgrades our plugin, our database is set up right. First we need to hook our function that is going to do that to the activation. We do this with the following code;<br />
<br/>
<pre class="php">register_activation_hook( __FILE__, 'qlist_activate' );</pre>
<p>Our function name is qlist_activate. Now its turn to create the function.</p>
<pre class="php">function qlist_activate() {
 global $wpdb;
 $qlist_db_version = "1.2";
 // Creating Questions Table
 $table_name = $wpdb-&gt;prefix . "qlists";
 if($wpdb-&gt;get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
	$sql = "CREATE TABLE " . $table_name . " (
	 `q_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
	 `question` VARCHAR( 250 ) NOT NULL ,
	 `q_order` INT NOT NULL
 );";

 // Creating Answers Table
 $answers_table_name = $wpdb-&gt;prefix . "qlists_answers";

 $sql .= "CREATE TABLE " . $answers_table_name . " (
	 `a_id` INT NOT NULL AUTO_INCREMENT  PRIMARY KEY ,
	 `q_id` INT NOT NULL ,
	 `u_id` CHAR ( 17 ) NOT NULL ,
	 `answer` INT NOT NULL
 );";
 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 dbDelta($sql);

 }

 $client_qlist_db_version = get_option('qlist_db_version');
 if($client_qlist_db_version!=$qlist_db_version){
	$answers_table_name = $wpdb-&gt;prefix . "qlists_answers";
	 $sql_up = "CREATE TABLE " . $answers_table_name . " (
	 `a_id` INT NOT NULL AUTO_INCREMENT  PRIMARY KEY ,
	 `q_id` INT NOT NULL ,
	 `u_id` CHAR ( 17 ) NOT NULL ,
	 `answer` INT NOT NULL
 );";
 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 dbDelta($sql_up);
 }

 add_option("qlist_db_version", $qlist_db_version); // If the database is ever needed to be updated
}</pre>
<p>We are going to do a database connection again so we need our global $wpdb in the first line. And right after that we&#8217;ve set up the version of our database.<br />
<br/><br />
First we create the table that is going to hold the questions in our list. We set the table name with the wpdb prefix with $table_name = $wpdb-&gt;prefix . &#8220;qlists&#8221;;<br />
<br/><br />
Now we check if the table is already created by just doing a show table statement in the database looking for our table name and if its not set we add our sql statement to create our table into a variable ($sql). Right after that we set the name for our answers table into a variable. Then we create an sql statement for that table and append that to our current $sql variable. Now the following two lines are important for versioning your database in WordPress. You need to call the upgrade.php file and then send your $sql into a function called dbDelta like I did in our example. This is fine if you are not planning on making any changes to your database in the future, which is probably not the case since there always is a change you might need.<br />
<br/><br />
Now we get the current version of our database if it is already set up with $client_qlist_db_version = get_option(&#8216;qlist_db_version&#8217;);<br />
<br/><br />
get_option is a function that gets an option that is set up in the WordPress options table in your database. You can use that table for other data too. Ill show you how to set data into that table on the last line of our activation function.<br />
<br/><br />
Now we compare our version of the tables to the version of our tables that are currently set. If an upgrade is needed we again create our sql statement that would create the table from scratch. Rest is simple, we call our upgrade file in and send our sql line to dbDelta function<br />
<br/><br />
NOTE: DO NOT CREATE AN UPGRADE STATEMENT, it should be a create table statement.<br />
<br/><br />
Now to create the option that is going to set the current db version into the WordPress options table; all you need to do is the following code;<br />
add_option(&#8220;qlist_db_version&#8221;, $qlist_db_version);<br />
<br/><br />
That concludes our administration section of our plugin. You can download the most current version of the plugin from <a href="http://wordpress.org/extend/plugins/q-lists-list-creator/">WordPress repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Show Popular Posts Without a Plugin</title>
		<link>http://www.weblimner.com/tutorial/show-popular-posts-without-a-plugin/</link>
		<comments>http://www.weblimner.com/tutorial/show-popular-posts-without-a-plugin/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 02:52:43 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[popular posts]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=189</guid>
		<description><![CDATA[This is probably the shortest way of showing the popular posts in your plugin and it is the same way I use on the sidebar of this blog. First of all open your functions.php file inside your theme folder. If it doesn&#8217;t exist, just create an empty file named functions.php in your current theme folder. [...]]]></description>
			<content:encoded><![CDATA[<p>This is probably the shortest way of showing the popular posts in your plugin and it is the same way I use on the sidebar of this blog.<br />
<span id="more-189"></span><br />
First of all open your functions.php file inside your theme folder.<br />
<em>If it doesn&#8217;t exist, just create an empty file named functions.php in your current theme folder.</em></p>
<pre class="php">function get_mostpopular(){
 global $wpdb;
 $popular_posts = $wpdb-&gt;get_results("SELECT id,post_title FROM {$wpdb-&gt;prefix}posts ORDER BY comment_count DESC LIMIT 0,5");
 foreach($popular_posts as $post) {
 if ($a%2){$turn='class="odd"';}else{$turn='';}
 print "&lt;li $turn&gt;&lt;a href='". get_permalink($post-&gt;id) ."'&gt;".$post-&gt;post_title."&lt;/a&gt;&lt;/li&gt;\n";
 $a++;
 }
}</pre>
<p>Copy this code between  tags. Currently this code shows 5 posts with the highest number of comments. If you want to show more just change the 3rd line where it says <em>comment_count DESC LIMIT 0,5</em> and replace 5 with the number you want.<br/><br/></p>
<p>Also I add a class &#8220;odd&#8221; to every other line to generate the different color on each line. Now save your functions.php and open up your sidebar.php.<br/><br/></p>
<p>And wherever you want to show the popular posts just call the function from there.<br />
<br/></p>
<pre class="php">&lt;ul&gt;&lt;?php get_mostpopular(); }?&gt;&lt;/ul&gt;</pre>
<p><br/><br/><br />
<strong>Extra:</strong></p>
<p>The current styles I use for this list is as follows;</p>
<pre class="css">#sidebar li{
	padding: 5px 15px;
	background-color:#f2f0f7;
	border-bottom:1px solid #fff;
}
#sidebar li.odd{background-color:#ebe8f1;}
</pre>
<p>You might want to change the &#8220;#sidebar&#8221; to the id or class of your own sidebar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/tutorial/show-popular-posts-without-a-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming up Post &#8211; Making of Q-List Plugin for WordPress</title>
		<link>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/</link>
		<comments>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 23:38:01 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Weblimner]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[q-list]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=183</guid>
		<description><![CDATA[I am working on a series of articles about the making of the Q-List List Creator plugin. I will divide the series into two. First one will be about the administration section and the second one will be about the user interface. Please let me know if you want anything else included into the articles [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a series of articles about the making of the <a href="http://wordpress.org/extend/plugins/q-lists-list-creator/">Q-List List Creator</a> plugin. I will divide the series into two. First one will be about the administration section and the second one will be about the user interface. Please let me know if you want anything else included into the articles so I can incorporate them as I write the article.<br/><br/></p>
<p>The series will have;<br/><br/></p>
<ul>
<li><strong><a href="http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/">Administration Section</a></strong>
<ul>
<li>Versioning your plugins database tables, and updating them</li>
<li>Creating your administration interface</li>
<li>Using wp options table in your database for your plugin options</li>
</ul>
</li>
<li><strong><a href="http://www.weblimner.com/plugin/making-of-q-list-plugin-for-wordpres-2-of-2/">User Interface</a></strong>
<ul>
<li>Using tags in your posts like [qlist]</li>
<li>Handling cookies for your plugin</li>
<li>Handling forms</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Number My Post Pages</title>
		<link>http://www.weblimner.com/plugin/number-my-post-pages/</link>
		<comments>http://www.weblimner.com/plugin/number-my-post-pages/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 19:14:15 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[Weblimner]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=87</guid>
		<description><![CDATA[This is our first public plugin that we put up on the WordPress plugin directory. What is it? Instead of using so many page numbers on your post page or having next and previous links, this plugin handles the pagination with a much more organized way. In the name version, you get an admin panel [...]]]></description>
			<content:encoded><![CDATA[<p>This is our first public plugin that we put up on the <a href="http://wordpress.org/extend/plugins/" target="_blank">WordPress plugin directory</a>.<br />
<span id="more-87"></span><br />
<br/><br/></p>
<h2>What is it?</h2>
<p>Instead of using so many page numbers on your post page or having next and previous links, this plugin handles the pagination with a much more organized way. In the name version, you get an admin panel with the ability to change the number of pages that shows, whether you want to show the dropdown or not and also you can choose to show the navigation panel if there is only one page or not.<br />
<br/><br/></p>
<h2>Screenshots</h2>
<p><img class="alignnone" title="Screenshot 1" src="http://www.weblimner.com/wp-content/uploads/2009/12/screenshot-1.gif" alt="" width="945" height="109" /><br />
<img class="alignnone" title="Screenshot 2" src="http://www.weblimner.com/wp-content/uploads/2009/12/screenshot-2.gif" alt="" width="535" height="86" /></p>
<div class="clear"></div>
<p><br/><br/></p>
<h2>How to use</h2>
<p>All you need to do is upload the plugin to your plugins directory just like any other WordPress plugin. Then you need to add the following line to your single.php for paging your posts and page.php for your paging your pages.</p>
<pre class="php">
&lt;?php mysinglepages(wp_link_pages(array('before' =&gt; '', 'after' =&gt; '', 'next_or_number' =&gt; 'number','echo' =&gt; '0'))); ?&gt;
</pre>
<p>Pretty much all you need to add is <span class="code">mysinglepages()</span> function around your page links function.<br />
<br/><br/></p>
<h2><a href="http://downloads.wordpress.org/plugin/number-my-post-pages-plugin.zip">Download</a></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/plugin/number-my-post-pages/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Object Caching 437/477 objects using disk

Served from: www.weblimner.com @ 2012-02-06 03:24:51 -->
