<?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>Notebook &#187; php</title>
	<atom:link href="http://www.mikemattner.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikemattner.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 18:51:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Code Snippets: Ad Display Function For Use in A CMS&#160;Template</title>
		<link>http://www.mikemattner.com/2012/01/code-snippets-ad-display-function-for-use-in-a-cms-template/</link>
		<comments>http://www.mikemattner.com/2012/01/code-snippets-ad-display-function-for-use-in-a-cms-template/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 00:00:25 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=3774</guid>
		<description><![CDATA[Since I was recently invited to be an AdPacks.com publisher, I had the pleasure of trying to find a way to integrate the ads tastefully into my site on the top level pages, as well as in individual posts. The current iteration of my site, as well as the last one, really only rely on [...]]]></description>
			<content:encoded><![CDATA[<p>Since I was recently <a href="http://www.mikemattner.com/?p=3709">invited to be an AdPacks.com publisher</a>, I had the pleasure of trying to find a way to integrate the ads tastefully into my site on the top level pages, as well as in individual posts. The current iteration of my site, as well as the last one, really only rely on the single column of content, so I lack a useful sidebar to place ads in; this pretty much limits me to placing ads in the content&#8211;well not quite in the content, but in the flow of content really.</p>
<p>So, I essentially needed ads to run after the first post, and only once on any page. In order to do that I needed a simple function that I could run in the <a href="http://codex.wordpress.org/The_Loop">WordPress loop</a>, and guarantee my requirements were met.</p>
<p>Thus, the <code>display_ads</code> function was born:</p>
<div class="code">
<pre><code>function display_ads(){
    global $ad_count;
	if($ad_count < 1){
      $display = 'AD CODE HERE';
	  echo $display;
	}
	$ad_count++;
}</code></pre>
</div>
<p>It's quick and dirty but pretty effective. Is there a better way to do this, because this is pretty much the quickest thing I could come up with on short notice? I am legitimately asking you, is there a better way?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2012/01/code-snippets-ad-display-function-for-use-in-a-cms-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weather? Here&#8217;s Your&#160;Weather</title>
		<link>http://www.mikemattner.com/2011/11/weather-heres-your-weather/</link>
		<comments>http://www.mikemattner.com/2011/11/weather-heres-your-weather/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 18:14:43 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[weather]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=3688</guid>
		<description><![CDATA[So, I got bored one day and decided that I wanted to make a weather widget for WordPress. Sort of. I thought that I needed one for a WordPress theme I was thinking about making. As per my previous experience, I couldn&#8217;t quite find one that fit the bill, and some were just downright cumbersome [...]]]></description>
			<content:encoded><![CDATA[<p>So, I got bored one day and decided that I wanted to make a weather widget for WordPress. Sort of. I thought that I needed one for a WordPress theme I was thinking about making. As per my previous experience, I couldn&#8217;t quite find one that fit the bill, and some were just downright cumbersome in implementation. A veritable nightmare.</p>
<p>When I first started development, I wasn&#8217;t too keen on what API/xml data feeds to use, so I went with the ever popular Weather.com XML data feed. Development was a bear because the terms of use were incredibly restrictive. You had to display their logo, which is fine, but then you HAD to display four links that were meant to generate click-throughs for them in some fashion; and all of this had to be visible near the weather data itself. Ok, I said to myself, I can deal with that, even if it makes the whole thing ugly.</p>
<div class="pull-4 span-4 pull-text">This whole thing is kind of funny to me. But hey, you have to monetize that data.</div>
<p>Two weeks later, they decided to end the free XML data service in favor of a different API model. I thought, &#8220;Excellent, I can finally develop something free of the cumbersome links and logos I was required to use before!&#8221; Not so fast. This service cost several hundred dollars a year. Not so good for me if I&#8217;m creating a plugin. Then I discovered Yahoo! Weather, ironically enough, powered by Weather.com&#8217;s data.</p>
<h3>Ok, get to it already, jerk.</h3>
<p>Fine, fine, fine. I simply thought that background information would be useful for you. With the previous version of this plugin, the version using Weather&#8217;s data, you were required to register with Weather.com in order to obtain a key that would allow you to access the data, and I had to build that in to the plugin. This version will work fine without it. Yay! Simplification! </p>
<p>However, your site is limited in the number of requests that can be made in a given day. So if you have a high traffic site you&#8217;ll run into issues if you&#8217;re constantly requesting data from Yahoo. I had to build in data caching in order to keep those requests down, so now you&#8217;ll only access the API once or twice every hour to update data and that should take care of the problem. So, it&#8217;s not instant, but probably good enough.</p>
<p>At the moment this plugin is a little hit and miss. I don&#8217;t plan on doing much more with it, but feel free to fork this, modify it, whatever.</p>
<p><a class="download_file" href="http://www.mikemattner.com/wp-content/uploads/2011/11/current-weather.zip" onClick="javascript: _gaq.push(['_trackPageview', 'current-weather.zip']);">Download Current Weather 1.5 (current-weather.zip)</a></p>
<p><a class="download_file" href="http://wordpress.org/extend/plugins/current-weather/" onClick="javascript: _gaq.push(['_trackPageview', 'Current Weather From WordPress']);">Download From the WordPress Repository</a></p>
<p>So, enjoy the fruits of my labor!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2011/11/weather-heres-your-weather/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending Email With&#160;PHPMailer</title>
		<link>http://www.mikemattner.com/2011/10/sending-email-with-phpmailer/</link>
		<comments>http://www.mikemattner.com/2011/10/sending-email-with-phpmailer/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 14:17:05 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHPMailer]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=3658</guid>
		<description><![CDATA[I&#8217;ve generally always handled forms with some quick and dirty php that used the standard mail() function to send me the resulting information. I never really got a good handle on setting that up properly, but, lucky for me, some one has done all of the dirty work by creating a class, PHPMailer, that was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve generally always handled forms with some quick and dirty php that used the standard <code>mail()</code> function to send me the resulting information. I never really got a good handle on setting that up properly, but, lucky for me, some one has done all of the dirty work by creating a class, <a href="https://code.google.com/a/apache-extras.org/p/phpmailer/">PHPMailer</a>, that was meant to handle emails quite a bit more extensively than I was able to do.</p>
<p>It&#8217;s actually fairly easy to get started using the class. This is the default implementation that the download provides for basic operation:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "This is for text based email"; // optional
$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}</code></pre>
</div>
</div>
<p>That is a very easy way to get up and running using the default <code>mail()</code> function. Most of the hard work has been done for you, all you&#8217;re left to do is to fill in the blanks. But hey, why go default when the thing provides you with some more advanced functionality? Like sending your email using SMTP.</p>
<p>The best way I found to handle my emails, and to send them using PHPMailer, was to create a component class, unoriginally named <code>mmEmail</code>, that would handle a few operations I needed in order to process the form and format the data.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>class mmEmail {
        var $name          = null;
        var $email         = null;
        var $message       = null;
	var $time          = null;
	var $SMTP_host     = null;
	var $SMTP_username = null;
	var $SMTP_password = null;
	var $send_to       = null;
	var $send_name     = null;
        var $subject       = null;

	static $instance;

        public function __construct() {
		self::$instance = $this;
	}

        public function format($message) {
           //code that formats the message body
        }

        //this function handles the message template
        public function template($template) {

		$name    = $this->name;
		$email   = $this->email;
		$message = $this->message;
		$time    = $this->time;

	        switch( $template ) {
		    case 'html' :
			    $the_body = $this->format($message);
	                    $body = 'html only';
				break;

			case 'text' :
		            $body = 'text only';
				break;

			default :
			    break;

		}

		return stripslashes($body);
	}

        public function send() {
            //code to handle PHPMailer - I'll get to it.
        }
}</code></pre>
</div>
</div>
<p>So this gets us set up to send our formatted email using the <code>send()</code> function above. That function uses PHPMailer to handle the heavy lifting.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>function send() {
    $html_body  = $this->template('html'); //HTML Body
    $text_body  = $this->template('text'); //Text only body

    require("class.phpmailer.php");
    $mail   = new PHPMailer();

    $mail->IsSMTP(); //SMTP
    $mail->Host     = $this->SMTP_host;
    $mail->SMTPAuth = true;
    $mail->Username = $this->SMTP_username;
    $mail->Password = $this->SMTP_password;

    $mail->From     = $this->email;
    $mail->FromName = $this->name;
    $mail->AddReplyTo($this->email, $this->name);
    $mail->AddAddress($this->send_to, $this->send_name);
    $mail->Subject = $this->subject;

    $mail->IsHTML(true);
    $mail->Body    = $html_body;
    $mail->AltBody = $text_body;

    $result = $mail->Send();

    if($result)
    {
        echo 'Mail sent.';
    }
    else
    {
        $result = $mail->ErrorInfo;
        return $result;
    }
}</code></pre>
</div>
</div>
<p>Using my class is then fairly straight forward. I&#8217;ll define a few constants for my settings to make things easier for me to read, and from there sending an email is as simple as:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>require("class.mmemail.php");
$email = new mmEmail();

$email->name          = NAME;
$email->email         = EMAIL;
$email->message       = MESSAGE;
$email->time          = TIME;
$email->SMTP_host     = SMTP_HOST;
$email->SMTP_username = SMTP_USERNAME;
$email->SMTP_password = SMTP_PASSWORD;
$email->send_to       = SEND_TO;
$email->send_name     = SEND_NAME;
$email->subject       = SUBJECT;

$email->send();</code></pre>
</div>
</div>
<p>Why do something this complicated, when the result looks so much like the original PHPMailer setup? Because this allows me to format, check, and sanitize my data and then send my emails using a template system. I encourage you to take a look at a solution like this the next time you need a better way to send form emails.</p>
<p class="small">
PHPMailer can be found at: <a href="https://code.google.com/a/apache-extras.org/p/phpmailer/">https://code.google.com/a/apache-extras.org/p/phpmailer/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2011/10/sending-email-with-phpmailer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating the Recent Custom Posts WordPress&#160;Widget</title>
		<link>http://www.mikemattner.com/2011/09/creating-the-recent-custom-posts-wordpress-widget/</link>
		<comments>http://www.mikemattner.com/2011/09/creating-the-recent-custom-posts-wordpress-widget/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 19:19:48 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[custom post types]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=3580</guid>
		<description><![CDATA[I recently found myself needing a way to display the most recent posts from multiple custom post types in multiple widgetized areas of a site I was working on. Because I needed to do this quickly, and I assumed this need was common, I was on the lookout for an already well written and developed [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found myself needing a way to display the most recent posts from multiple custom post types in multiple widgetized areas of a site I was working on.</p>
<p>Because I needed to do this quickly, and I assumed this need was common, I was on the lookout for an already well written and developed plugin that would do the job. I ran across a <a href="http://new2wp.com/pro/latest-custom-post-type-posts-sidebar-widget/">widget plugin from New2WP</a> that allowed you to display the most recent posts from a single custom post type. Unfortunately, it wasn&#8217;t a multi-widget and you could only select one post type, so the plugin wasn&#8217;t suitable.</p>
<div class="pull-text">This is a <a href="http://new2wp.com/pro/latest-custom-post-type-posts-sidebar-widget/">fine plugin</a>, it just needs to be multi-widget capable to be more useful.</div>
<p>My first thought was that I could easily turn the plugin into a multi-widget capable plugin, but when I started to work on it, I realized that any modifications I made could easily be overwritten on the next update. Additionally, when I began work on turning it into a multi-widget plugin, it became exceedingly obvious that I would probably need to start from scratch.</p>
<p>That&#8217;s when I decided to develop a plugin of my own, based on the structure of what I saw in the plugin from New2WP, that would fit my needs, and hopefully the needs of others.</p>
<h3>Where to Begin</h3>
<div class="pull-4 span-4 pull-text">Visit the <a href="http://codex.wordpress.org/Widgets_API">Widgets API</a> reference at the WordPress codex for a better overview of this information.</div>
<p>Once I figured out that I needed to turn the widget into one that could be used in multiple widgetized areas, I started to research like mad to find out what it would take to accomplish this. One trip over to the WordPress codex was enough to send me in the right direction.</p>
<p>It was basically as simple as this default usage code implies:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>class My_Widget extends WP_Widget {
	function My_Widget() {
		// widget actual processes
	}

	function form($instance) {
		// outputs the options form on admin
	}

	function update($new_instance, $old_instance) {
		// processes widget options to be saved
	}

	function widget($args, $instance) {
		// outputs the content of the widget
	}

}
register_widget('My_Widget');</code></pre>
</div>
</div>
<p>However, converting the existing plugin to this wasn&#8217;t as simple as the above code implies. The old plugin was built as a function, and its structure made it quite a bit more difficult to tie into the WordPress Widgets API.</p>
<p>Based on what I learned from New2WP&#8217;s plugin, and the WordPress Codex, I proceeded to build out my own plugin.</p>
<h3>The Recent Custom Posts Plugin</h3>
<p>I started by creating the directory <code>/mm-recent-cpt/</code>, the file <code>mm-recent-cpt.php</code>, and <code>readme.txt</code> file for future upload to the WordPress plugin directory.</p>
<p>In the <code>php</code> file I added the plugin header:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>/**
 * Plugin Name: Recent Custom Posts
 * Plugin URI: http://mikemattner.com/custom-post-type-widget/
 * Description: Multi-widget for displaying recent posts of custom post types.
 * Version: 1.0
 * Author: Mike Mattner
 * Author URI: http://www.mikemattner.com/
 * Tags: custom post types, post types, latest posts, sidebar widget, plugin
 * License: GPL
 */</code></pre>
</div>
</div>
<p>This allows WordPress to gather information about your plugin. If you just put that file into the plugins directory right now, you&#8217;ll have a plugin that does nothing, but it will show up in the list.</p>
<p>The structure of this widget is fairly simple because of the Widgets API. You&#8217;ll create a class that extends the <code>WP_Widget</code> class, essentially making it a breeze to create this plugin. I named my class <code>mm_recent_posts</code>. In order to get things moving, you need to initialize the plugin. In most cases you&#8217;ll use <code>add_action</code> to get your class or function working.</p>
<p>The function I&#8217;m calling with <code>add_action</code> returns <code><a href="http://codex.wordpress.org/Function_Reference/register_widget">register_widget</a></code>, which takes the <code>$widget_class</code> argument. According to the Codex, <code>$widget_class</code> is the name of a class that extends <code>WP_Widget</code>.</p>
<p>So, this is my basic structure:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>add_action( 'widgets_init', 'init_mm_recent_posts' );
function init_mm_recent_posts() { return register_widget('mm_recent_posts'); }

class mm_recent_posts extends WP_Widget {
    /** constructor */
    function mm_recent_posts() {
       parent::WP_Widget( 'widget_recent_cpt', $name = 'Recent Custom Posts' );
    }

    function widget($args, $instance) {
       // outputs the content of the widget
    }

    function update($new_instance, $old_instance) {
       // processes widget options to be saved
    }

    function form($instance) {
       // outputs the options form on admin
    }

}</code></pre>
</div>
</div>
<p>The above is fairly self-explanatory as far as what each function&#8217;s purpose is. The constructor function <code>mm_recent_posts()</code> is designed to give a little information about the widget. You could use something along these lines to get it up and running: <code>parent::WP_Widget('my_widget_base', 'My Widget title', array('description' => 'Very simple widget example', 'class' => 'my-widget-class'));</code>.</p>
<p>Pretty easy, right?</p>
<h3>The Plugin</h3>
<div class="push-8 span-8">
   <img src="http://www.mikemattner.com/wp-content/uploads/2011/09/widget.png" alt="" title="widget" width="254" height="254" />
</div>
<p>The plugin I created is fairly straightforward. It is essentially just an extension of the original Recent Posts widget that comes with WordPress by default&#8211;except that this doesn&#8217;t overwrite that.</p>
<p>If this looks like something you could use, feel free to download, use, and modify till you&#8217;re blue in the face.</p>
<p><a class="download_file" href="http://www.mikemattner.com/wp-content/uploads/2011/09/recent-custom-posts.1.0.1.zip" onClick="javascript: _gaq.push(['_trackPageview', 'recent-custom-posts.zip']);">Download Recent Custom Posts Plugin 1.0.1 (recent-custom-posts.1.0.1.zip)</a></p>
<p><a class="download_file" href="http://wordpress.org/extend/plugins/recent-custom-posts/">Download From WordPress Plugin Directory</a></p>
<div class="pull-4 span-4 pull-text">I&#8217;ve now uploaded the plugin to the WordPress <a href="http://wordpress.org/extend/plugins/recent-custom-posts/">plugin directory</a>. I hope you&#8217;ll find it to be useful.</div>
<p><del datetime="2011-09-08T14:31:41+00:00">I&#8217;m working on getting this added to the WordPress plugin repository</del> The plugin can also be downloaded from the WordPress plugin repository. If you have any questions, comments, or modifications, let me know in the comments. I can&#8217;t guarantee that this will work with all plugins, particularly the <a href="http://wordpress.org/extend/plugins/custom-post-type-ui/">Custom Post Type UI plugin</a>, but I will say that I&#8217;ve used it, and it works for me. I apologize if my code isn&#8217;t up to snuff.</p>
<p><em>Also, <strong>welcome Stumblers!</strong> Thanks for stopping by. Hopefully you&#8217;ll find my little plugin to be useful.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2011/09/creating-the-recent-custom-posts-wordpress-widget/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Overwriting WordPress&#160;Functions</title>
		<link>http://www.mikemattner.com/2010/01/overwriting-wordpress-functions/</link>
		<comments>http://www.mikemattner.com/2010/01/overwriting-wordpress-functions/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 06:14:59 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=1348</guid>
		<description><![CDATA[WordPress finds new ways to amaze me; some of these things are neither impressive nor particularly noteworthy, except that these things enable users to customize this platform in ways unimaginable to regular Joe Blogger, who simply uses the system. And in spite of how common such things are to those who truly dive into it, [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress finds new ways to amaze me; some of these things are neither impressive nor particularly noteworthy, except that these things enable users to customize this platform in ways unimaginable to regular Joe Blogger, who simply uses the system. And in spite of how common such things are to those who truly dive into it, I struggled for quite a while trying to find the best way to change a bit of core functionality.</p>
<div class="pull-4 span-4 pull-text"><strong>Note:</strong> I want to caution you to avoid doing anything with WordPress&#8217; core functions if you aren&#8217;t familiar with php. You will regret it, especially if you&#8217;ve done something directly to a core file. Stick with filtering and extending with plugins.</div>
<p>If you scroll down to the bottom of the site on the home page, and on any entry page, you&#8217;ll notice a set of buttons that will help you navigate to the next and previous entries, or the next and previous pages of the home page. I needed a way to style these, and oddly enough WordPress did not provide a class name for either of those links. Too bad. So I needed to find out how to adjust that in order to target those links. In addition to that, I needed to also make a small change that classes wouldn&#8217;t have allowed for, which was to get the function to output code for the cases in which there were no other pages or posts in a given direction. My first thought was to find whatever core file these functions were located in and then make the change there; I proceeded to do this, got it working, and decided that I should go about this in a different way if I ever wanted to upgrade without having to change that file every time&#8211;if I even remembered in those instances.</p>
<p>The tags in question were: <code>next_posts_link</code>, <code>previous_posts_link</code>, <code>next_post_link</code>, and <code>previous_post_link</code>, as well as a few more functions that were related to them. Each of these provides the basic functionality I needed to modify; I tried to replicate these functions, using the same name, in an effort to essentially overwrite the original WordPress core functions. Well, I located them in the link-template.php file, copied and pasted them into my themes functions.php file, and proceeded to make the necessary changes. When I uploaded functions.php and refreshed my site, I had a big giant error; actually it was less an error and more a blank screen, which is worse in a lot of ways as you have no idea what went wrong. I should have known from my programming experience that I couldn&#8217;t duplicate these functions in this way.</p>
<p>I was stumped for the longest time, and search after search on Google was leading me towards something called, <code>add_filter</code>, which it turns out doesn&#8217;t quite overwrite the function so much as filter the function results through your new function; this was not what I wanted to do on any level. I couldn&#8217;t manipulate the data through a filter to achieve the needed results.</p>
<p>After some time, and a lot of searching, I landed on a WordPress MU forum (still not sure what MU is), that gave me my answer&#8211;the most obvious answer&#8211;which was to take the functions I needed and rename them. I could then use those new function names in place of the old ones wherever I needed them in my theme files.</p>
<p>That&#8217;s easy, ain&#8217;t it? Why don&#8217;t people explain this more often, or even need to to do this enough for it to be found on Google?</p>
<p><strong>Update 1/19/2010</strong>: I wanted to clarify just in case some one stumbled upon this looking for an actual bit of code that might show them what I was up to. So here goes.</p>
<p>Instead of adding a filter to the function you want to change:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>add_filter('next_posts_link', 'new_next_posts_link', 0);</code></pre>
</div>
</div>
<p>Add a new function to functions.php and call it in your template wherever you were going to use the old one.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>function new_get_next_posts_link( $label = 'Next Page &amp;raquo;', $max_page = 0 ) {
    global $paged, $wp_query;

    if ( !$max_page ) {
        $max_page = $wp_query-&gt;max_num_pages;
    }

    if ( !$paged )
    $paged = 1;

    $nextpage = intval($paged) + 1;

    if ( !is_single() ) {
        if( empty($paged) || $nextpage &lt;= $max_page) {
            $attr = apply_filters( 'next_posts_link_attributes', '' );
            return '&lt;a href="' . next_posts( $max_page, false ) . "\" class=\"next\" $attr&gt;". preg_replace('/&amp;([^#])(?![a-z]{1,8};)/', '&amp;#038;$1', $label) .'&lt;/a&gt;';
        } else {
            $attr = apply_filters( 'next_posts_link_attributes', '' );
            return '&lt;span '.$attr.'&gt;'. preg_replace('/&amp;([^#])(?![a-z]{1,8};)/', '&amp;#038;$1', $label) .'&lt;/span&gt;';
        }
    }
}
function new_next_posts_link( $label = 'Next Page &amp;raquo;', $max_page = 0 ) {
    echo new_get_next_posts_link( $label, $max_page );
}﻿</code></pre>
</div>
</div>
<p>I&#8217;ve essentially adjusted this line:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>if ( !is_single() &amp;&amp; ( empty($paged) || $nextpage &lt;= $max_page) ) {
    $attr = apply_filters( 'next_posts_link_attributes', '' );
    return '&lt;a href="' . next_posts( $max_page, false ) . "\" $attr&gt;". preg_replace('/&amp;([^#])(?![a-z]{1,8};)/', '&amp;#038;$1', $label) .'&lt;/a&gt;';
}﻿</code></pre>
</div>
</div>
<p>And changed it to this next bit in order to add a class to the link for styling purposes as well as to display a grayed out link if there was no next (or previous in the case of those set of functions) page.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>if ( !is_single() ) {
    if( empty($paged) || $nextpage &lt;= $max_page) {
        $attr = apply_filters( 'next_posts_link_attributes', '' );
        return '&lt;a href="' . next_posts( $max_page, false ) . "\" class=\"next\" $attr&gt;". preg_replace('/&amp;([^#])(?![a-z]{1,8};)/', '&amp;#038;$1', $label) .'&lt;/a&gt;';
    } else {
        $attr = apply_filters( 'next_posts_link_attributes', '' );
        return '&lt;span '.$attr.'&gt;'. preg_replace('/&amp;([^#])(?![a-z]{1,8};)/', '&amp;#038;$1', $label) .'&lt;/span&gt;';
    }
}</code></pre>
</div>
</div>
<p>So, again. If you&#8217;ve got something to modify, do it this way. The functions.php template file is your best friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2010/01/overwriting-wordpress-functions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress vs MovableType: My&#160;Experience</title>
		<link>http://www.mikemattner.com/2009/04/wordpress-vs-movabletype-my-experience/</link>
		<comments>http://www.mikemattner.com/2009/04/wordpress-vs-movabletype-my-experience/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 15:40:07 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[Movable Type]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/notebook/?p=22</guid>
		<description><![CDATA[I’ve been working on a bit of a personal project lately and decided the easiest and best way to introduce a blog would be to install WordPress, plus I really wanted to give that system a little more of a try than I had in the past. My gut reaction upon installing and settling on [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on a bit of a personal project lately and decided the easiest and best way to introduce a blog would be to install WordPress, plus I really wanted to give that system a little more of a try than I had in the past.</p>
<p>My gut reaction upon installing and settling on a theme for modification was that this was REALLY easy to work with and highly customizable. I had, in fact, gotten used to working with my own MovableType installation, its quirks, and its own templating system, but the php based WordPress on my server was a breeze to deal with compared to the former. It was faster, offered better plugins, easier templating, and I could even edit the hell out of those plugins to customize the installation even further for my needs.</p>
<p>I’m so convinced by my experience that WordPress is the superior publishing platform for anyone looking to get started beyond the free services and put up a site on their own domain, that I am absolutely going to develop the next iteration of this site with WordPress in mind.</p>
<p>MovableType has been good to me, and it truly is a very powerful platform, but my servers don’t deal with it, and it is SLOW as a result. Plus, all of the plugins I want to use aren’t offered for MT or don’t offer what I need. And that can be frustrating.</p>
<p>What I like about MT, though, is the publishing experience. I feel like I can easily add tags to any entry with little problem, and the interface (MT 4.0+ at least) is minimal and easy to use. Previous versions were a bear to work with, I’m afraid, but 4.0+ is quite fantastic.</p>
<p>Anyway, my conclusion: WordPress for the future iteration, but MT will suffice for now; WordPress is superior to MT for beginners and its ease of use; and MT is not likely to catch up.</p>
<p><em><strong>Update:</strong> 5/15/09 I am currently in the process of converting to WordPress. Manually. Really frustrating, but worthwhile. I&#8217;ve also discovered that it is a superior publishing experience.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2009/04/wordpress-vs-movabletype-my-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery AJAX Form&#160;Submission</title>
		<link>http://www.mikemattner.com/2008/12/jquery-ajax-form-submission/</link>
		<comments>http://www.mikemattner.com/2008/12/jquery-ajax-form-submission/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 23:54:55 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=253</guid>
		<description><![CDATA[I&#8217;ve never been much of a programmer; and I&#8217;m probably unusually intimidated by JavaScript. I can&#8217;t explain its effect on me, considering what I&#8217;ve tackled with php (which, I suppose is arguably pretty simple and inefficient stuff), but it&#8217;s not something I&#8217;m proud of. At any rate, this week I decided to tackle a bit [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never been much of a programmer; and I&#8217;m probably unusually intimidated by JavaScript. I can&#8217;t explain its effect on me, considering what I&#8217;ve tackled with php (which, I suppose is arguably pretty simple and inefficient stuff), but it&#8217;s not something I&#8217;m proud of.</p>
<p>At any rate, this week I decided to tackle a bit of a problem that has been bothering me for as long as I&#8217;ve had the current design on my portfolio site.<br />
The portfolio side of things exists as a single page site with work samples, a little information, and a contact form. The contact form would require that you reload the page upon submission in order to process and send the message, which always seemed like a jarring experience from a user interaction perspective.<br />
In order to solve that problem, my solution was the ever popular: <a href="http://en.wikipedia.org/wiki/AJAX">AJAX</a>.</p>
<p>I&#8217;ve used some jQuery plugins in the past, so I was familiar with the framework; after doing some reading and thinking about compatibility with my current setup, I decided that jQuery&#8217;s built in AJAX implementation, and animation effects, would be just about perfect for my needs. Why? Because the jQuery framework is incredibly useful to me, as a designer, with little time for figuring out how to implement all of these fancy user interactions with JavaScript. Plus, it&#8217;s the framework I use for everything.</p>
<p><span id="more-253"></span></p>
<h4>Let&#8217;s Get Programming</h4>
<p>Where does my implementation begin? Well it begins by adding the jQuery files to the head of your page:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>&lt;script type="text/javascript" src="path/to/jquery.js"&gt;&lt;/script&gt;</code></pre>
</div>
</div>
<p>Then we&#8217;ll setup the function that will help us load up what we need. This is the function we will place all of our jQuery code in:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$(document).ready(function(){
   <span>//some code</span>
});
</code></pre>
</div>
</div>
<p>jQuery is nice for many reasons, one being the way in which events are initiated. [Karl Swedberg](http://www.learningjquery.com/2006/09/introducing-document-ready) says:</p>
<blockquote><p>The $(document).ready() function has a ton of advantages over other ways of getting events to work. First of all, you don&#8217;t have to put any &#8220;behavioral&#8221; markup in the HTML. You can separate all of your javascript/jQuery into a separate file where it&#8217;s easier to maintain and where it can stay out of the way of the content.</p></blockquote>
<p>That&#8217;s useful for content/style/function separation, and is really, really handy. And perhaps one of the reasons I avoided JavaScript for so long was because it lacked something this simple to begin with.</p>
<h4>Let&#8217;s start the AJAX</h4>
<p>So first we need to setup what it is we&#8217;re going to be evaluating, which is basically the submit event of form <code>#contactform</code>. When we click submit, our function will run.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$("form#contactform").submit(function() {
   <span>//some code</span>
});
</code></pre>
</div>
</div>
<p>This function will have to do a number of things for us. First it needs to store our input values into variables in order to process them and POST them later. Then we&#8217;ll take those input variables and place them all in a variable (<code>formData</code>) formatted for ease of use for the POST process.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>var name     = $('#name').attr('value');
var formData = "name="+ name + "&#038;email=" + <span>--></span>
email + "&#038;message=" + message + "&#038;color=" + color;
</code></pre>
</div>
</div>
<p>Following this bit of code it&#8217;s time to use <code>jQuery.ajax</code> in order to submit our form information asynchronously.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$.ajax({
   type: "POST",
   url: "send.php",
   data: formData,
   success: function(del){
      <span>//success code placed here</span>
   }
});
</code></pre>
</div>
</div>
<p>The options for <code>jQuery.ajax</code> in my code here are: type, the method that will be used when sending the form data, in this case POST; url, or the location where we will be sending our form data; data, the data to be sent; and success, what will we do when it has completed successfully. Check out <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options">jQuery.ajax</a> for more information on options.</p>
<p>That&#8217;s pretty much it. I&#8217;ve setup the PHP file to deal with the posted data, and there are many ways to do this, so use your favorite and do it in the way you normally would.</p>
<h4>My Code</h4>
<p>Ok, so in my code, I&#8217;ve done a bit of rudimentary form field validation and bot protection. Additionally, I&#8217;ve added a little bit of effect animation and utilized the DOM to display confirmation or error messages, a loading graphic, and to fade out certain elements of the form. I discovered a bit of a problem when my inbox was full of spam messages from this form. In my PHP file, I&#8217;ve had to add a little bit of validation there as well, in case a user, or a bot, is attempting to the use the form without JavaScript enabled.</p>
<p>The JavaScript:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$(document).ready(function(){
$("form#contactform").submit(function() {
    var name     = $('#name').attr('value');
    var email    = $('#email').attr('value');
    var message  = $('#message').attr('value');
    var color    = $('#color').attr('value');
    var formData = "name="+ name + "&#038;email=" + email + "&#038;message=" + message + "&#038;color=" + color;
    $('#contact_form > div#error').hide("fast");
    $('#contact_form > div#success').hide("fast");
    $('#contact_form > div#problem').hide("fast");
    <span>//Test whether fields have been filled and rudimentary bot test has passed then send via jquery.ajax</span>
    if (name != null &#038;&#038; email != null &#038;&#038; message != null) {
        if (color == "blue" || color == "Blue"){
            $("#contactform").before('&lt;div id="loading" style="text-align:center;"&gt;&lt;img src="images/loadingForm.gif" /&gt;&lt;/div&gt;').slideDown("fast");
            $("#submitButton").hide();
            $("#contactform").fadeTo("fast", 0.33);
            $.ajax({
                 type: "POST",
                 url: "send.php",
                data: formData,
                success: function(del, text){
                      $("form#contactform").before('&lt;div class="error" id="success"&gt;Thank you for your message!&lt;/div&gt;').slideDown("slow");
                      $('#name').attr('value', '')
                      $('#email').attr('value', '')
                      $('#message').attr('value', '')
                      $('#color').attr('value', '')
                      $('#contact_form > div#loading').slideUp("slow");
                      $("#submitButton").show();
                      $("#contactform").fadeTo("slow", 1);
                }
            });
        }else{
            $("#contactform").before('&lt;div class="error" id="error"&gt;You must fill in the color of the sky!&lt;/div&gt;').slideDown("slow");
            $('#contact_form > div#loading').slideUp("fast");
            $("#submitButton").show();
            $("#contactform").fadeTo("fast", 1);
        }
    } else {
        $("#contactform").before('&lt;div class="error" id="problem"&gt;You must fill in all of the fields!&lt;/div&gt;').slideDown("slow");
        $('#contact_form > div#loading').slideUp("fast");
        $("#submitButton").show();
        $("#contactform").fadeTo("fast", 1);
    }
        return false;
    });
});
</code></pre>
</div>
</div>
<p>The form:</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>&lt;form name="contact_form" id="contactform" method="post" action="send.php"&gt;
&lt;div class="column span-4 first last"&gt;
&lt;label for="name"&gt;Full Name:&lt;/label&gt;
&lt;input type="text" id="name" class="textfield" name="name" value="" /&gt;
&lt;/div&gt;
&lt;div class="column span-4 first last"&gt;
&lt;label for="email"&gt;Email: &lt;/label&gt;
&lt;input type="text" id="email" class="textfield" name="email" value="" /&gt;
&lt;/div&gt;
&lt;div class="column span-4 first last"&gt;
&lt;label for="color"&gt;What color is the sky? &lt;/label&gt;
&lt;input type="text" id="color" class="textfield" name="color" value="" /&gt;
&lt;/div&gt;
&lt;div class="column span-4 first last"&gt;
&lt;label for="message"&gt;Message:&lt;/label&gt;
&lt;textarea class="textfield" id="message" name="message" cols="10" rows="8"&gt;&lt;/textarea&gt;
&lt;/div&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;div class="text-right" id="submitButton"&gt;
&lt;input type="image" name="send" value="Send" src="images/submit.gif"/&gt;
&lt;/div&gt;
&lt;/form&gt;
</code></pre>
</div>
</div>
<h4>Conclusion</h4>
<p>That&#8217;s all I&#8217;ve done. I&#8217;m no programmer, and I apologize for not knowing how to best explain what I&#8217;ve done, but hopefully getting a chance to look at some code will help you figure it out. If you have questions, I would be glad to help as much as I can.</p>
<p>Special thanks to <a href="http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/">Ryan Coughlin</a> for helping me through this by offering up his code, which is what I based my AJAX form on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2008/12/jquery-ajax-form-submission/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Functions and Me: Gallery&#160;Layout</title>
		<link>http://www.mikemattner.com/2008/04/functions-and-me-gallery-layout/</link>
		<comments>http://www.mikemattner.com/2008/04/functions-and-me-gallery-layout/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 00:13:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[Gallery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=203</guid>
		<description><![CDATA[As of recently, I&#8217;ve had a particular layout for my gallery section that just wasn&#8217;t working for me. Well, it was probably OK, and I generally approved of it&#8211;since I designed it at some point&#8211;but I always thought it felt awkward. I&#8217;ve had the thought running through my head for a few weeks now that [...]]]></description>
			<content:encoded><![CDATA[<p>As of recently, I&#8217;ve had a particular layout for my gallery section that just wasn&#8217;t working for me. Well, it was probably OK, and I generally approved of it&#8211;since I designed it at some point&#8211;but I always thought it felt awkward.</p>
<p>I&#8217;ve had the thought running through my head for a few weeks now that it would probably be a good idea to adjust the layout; perhaps to spice it up, or make it a little more pleasing to my eye. Maybe this is perfectionism kicking in, but I really enjoy making these adjustments and experimenting in how I go about completing them.</p>
<p>What I initially decided to do was adjust the teaser image size by widening all of them to fill the entire 9 column width&#8211;which is the size of my primary content section (I have designed this site based on a 24 column, 936px wide grid). Because of that adjustment, I have had to change the way I display each project&#8217;s summary information. There are still many adjustments to be made, but so far so good.</p>
<p>What I&#8217;m most proud of in all of this change, however, has nothing to do with what is ultimately displayed. No, what is most impressive lies underneath it all. That&#8217;s right, I&#8217;ve gone and done something completely unnecessary&#8211;albeit, very cool&#8211;in the gallery display options I currently possess.</p>
<p>I initially didn&#8217;t want to commit to the larger size, so I created a bunch of backups of my CSS files and various source code files just in case I wanted to switch back, but why the hell was I doing that when I could write a bunch of functions that would do it for me?</p>
<p>On my workpage, in order to display the gallery, I include a file that possesses all of the appropriate php; in this way, if I need to make an adjustment, it&#8217;s pretty easy to go through and change whatever code I need. But there was one part in particular that became a bit of a hassle to adjust. Whenever I needed make a quick layout adjustment, I had to wade through three different files to do it&#8211;chalk it up to my inexperience I guess.</p>
<p>To alleviate the mess, I took that section and turned it into a function that would produce that section for me; now I could separate it from that file and consolidate everything, putting it all into one central location for quick adjustment action.</p>
<p>In the file that contains my primary functions and controls page numbers and gallery categories, I included the newly created function (small layout size) and created another (large layout size) that I would use based on a couple of different settings variables. I also set it up so my CSS file is created on the fly&#8211;that is the one that would determine which CSS files to <code>@import</code>.</p>
<p>Because of this simple little setup, I&#8217;m able to switch between those two different layouts in about five seconds, plus any adjustments in the future will be a matter of adjusting a couple of functions.</p>
<p>That&#8217;s just easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2008/04/functions-and-me-gallery-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying my Portfolio Pieces with&#160;PHP</title>
		<link>http://www.mikemattner.com/2008/04/displaying-my-portfolio-pieces-with-php/</link>
		<comments>http://www.mikemattner.com/2008/04/displaying-my-portfolio-pieces-with-php/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 01:48:31 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Entries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.mikemattner.com/?p=196</guid>
		<description><![CDATA[When I set out to work on the current version of my website and portfolio, I initially displayed my work in much the same way as I displayed it in the last version. All of my pieces were in smaller thumbnail versions and each one (about 30 at the time) were displayed on one page; [...]]]></description>
			<content:encoded><![CDATA[<p>When I set out to work on the current version of my website and portfolio, I initially displayed my work in much the same way as I displayed it in the last version. All of my pieces were in smaller thumbnail versions and each one (about 30 at the time) were displayed on one page; I had pagination ready to rock and roll, but with the format the thumbnails were in and the lack of real information being displayed about every piece, it didn&#8217;t make a whole lot of sense to use it.</p>
<p>Moving forward on this design was pretty straightforward, but I stuck with the old way initially because I had built a pretty intricate system to handle my portfolio. Not that it was difficult to adjust, just that it would take me a little time to swap things out.</p>
<p>When it came down to it, though, my final design on the portfolio on this version required something a little more sophisticated than what I had set up. I needed to be able to adjust how everything functioned, and quickly. I also wanted it to be quickly and easily customizable.</p>
<p>A quick run down of what I wanted to do:</p>
<ol>
<li>I wanted to be able to use the system I had already built to add, edit, and delete portfolio pieces quickly and easily.</li>
<li>I wanted to use the information in the database that I had never displayed before but had built into the system.</li>
<li>I wanted to be able to display all of the pieces by their project type.</li>
<li>Finally, I wanted to utilize pagination for the overall portfolio, and for each category of project.</li>
</ol>
<p>All of this could be accomplished, but it was going to require a whole lot more than I was truly prepared for, because I&#8217;m not much of a programmer. I knew some things, in php, and I knew how to accomplish those things with some very basic straightforward programming. This time, though, I needed to make some custom functions. This was going to be the only way to make this work. It might not be necessary, or accurate, but I was going to try my hand at OOP (something that isn&#8217;t really needed for this application, but something I did anyway).<br />
Prepare, programmers, to be unimpressed.</p>
<p><span id="more-196"></span></p>
<h4>The Details</h4>
<p>First things first I created an array to handle my various project types. This way I could add more or remove them easily if I needed to. Following that, I created a variable that would hold the final count of the items in the array (making it easier for me to run through them later when I&#8217;ll need them). Finally, I created the class <code>DoIt{}</code> in order to hold a couple of the functions I&#8217;ll need to use later.</p>
<p>I later added a function that a) checks to see if some variable exists and then b) counts that item. I use it to make sure that two particular array counts agree with each other; this is useful for checking errors in my gallery.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$cat = array('Illustration', 'Web', 'Email', 'Print', 'Advertisement');
$arr = count($cat)-1;
class DoIt {
    function countMe($t) {
        if(isset($t)){
            $ct = count($t);
        }
        return $ct;
    }
}
</code></pre>
</div>
</div>
<p>The first two functions I need are setup to test what category is displayed and what will be displayed as a result; these are pretty simple, because they just display a little menu of category options for me, wherever I happen to place them.</p>
<p>The most important function was one that I had actually created for the last version of my website. Because I had already built it and worked out the kinks, I was able to reuse the code&#8211;no tweaks necessary. This function was used to handle pagination and the display of page numbers. I wanted to use this function so that I could place the page numbers anywhere, multiple times within a document just by inserting <code>$DoIt-&gt;paginateMe()</code> anywhere.</p>
<p>After all of those functions were placed in the  <code>DoIt()</code> class, I had to initiate a new object with: <code>$DoIt = new DoIt;</code>.<br />
One thing I tend to do with all of the websites I build with php is to set a base directory variable; this way I can ensure that items are always linked properly, no matter where they reside in the site&#8217;s directory structure&#8211;just in case I screw  up and put something somewhere other than where I expect. So in this case I insert <code>$base = "http://www.mikemattner.com/";</code> next.</p>
<p>Now that I have all of that functionality ready to go, I need to connect to the database (in my case MySQL) in order to grab all of that portfolio information. I create an array that holds all of my connection information (hostname, username, password, and database). I can then use it to connect to MySQL and select the appropriate database.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$server = array(
        'host' => 'HOSTNAME',
        'username' => 'USERNAME',
        'password' => 'PASSWORD',
        'database' => 'DATABASE');
mysql_connect($server['host'], $server['username'], $server['password']);
@mysql_select_db($server['database']);
</code></pre>
</div>
</div>
<p>After I&#8217;ve connected to the database I run a couple of different queries. The first is to grab some information from a table I have setup that holds a few gallery settings like: how many items to display per page, the gallery thumbnail directory, and the gallery image directory. I put that information into an array to be used in various places throughout the rest of the script.</p>
<p>The second, and most important query I run is to grab all of my gallery information from the database. Information like: the various file names needed, the title, the description, technologies used on the project, etc. This one comes with a twist because I have to run the query based on what the user is browsing (i.e. what category have they selected if any). After I&#8217;ve run the query, the information is put into an array, safely tucked away for use in a little while.</p>
<p>Once I&#8217;m done with all of that, I close out the connection.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$query_set   = "SELECT * FROM table_settings WHERE id='1'";
$query_set_result  = mysql_query($query_set);
$the_settings = mysql_fetch_row($query_set_result);
$thumb_dir        = $the_settings[1];
$link_dir         = $the_settings[2];
$display_count    = $the_settings[3];
if(isset($_GET['category'])){
    $category= $_GET['category'];
    if ($category== "all") {
        unset($category);
        $query_dis  = "SELECT * FROM table_display";
    } else {
        $query_dis  = "SELECT * FROM table_display WHERE type = '" . $category. "'";
    }
} else {
    $query_dis  = "SELECT * FROM table_display";
}
$the_result = mysql_query($query_dis);
$row_count      = mysql_num_rows($the_result);
$r = 0;
while ($row = mysql_fetch_array($the_result, MYSQL_BOTH)) {
$info[table_column][$r]                = $row[0];
<span>//I run through 11 items here</span>
$r++;
}
mysql_close();
</code></pre>
</div>
</div>
<p>The next section determines what page number we&#8217;re on and how to display the various items (such as where to start or end) on each page. Basically, I evaluate the page number based on whether or not it has been sent via GET; if it has, I grab it and use that to run through the various settings.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>if(isset($_GET['page'])){
$page = $_GET['page'];
}
if(empty($page)){
$page = 1;
}
if($page == 1){
$tot = $row_count-1;
$bar = $row_count - $display_count;
$g   = $display_count;
} else {
$tot = ($row_count-1) - (($page-1) * $display_count);
$bar = ($tot - ($display_count))+1;
if($bar < 0){
$bar = 0;
}
$g   = $row_count - $bar;
}
</code></pre>
</div>
</div>
<p>The rest is pretty straight forward. I use the <code>countMe()</code> function to count whether or not the items in the gallery item array match up. If they do then I display the items, if they don't then an error has occurred that I need to look into. I use a <code>for</code> loop to run through and display the gallery items. All in all, its pretty simple.</p>
<div class="pull-4 span-18">
<div class="code">
<pre><code>$a = $DoIt->countMe($gallery[thumbs]);
$b = $DoIt->countMe($gallery[links]);
if( $a == $b ){
if ($b < $display_count) {
$tot = $b-1;
$bar = 0;
}
$DoIt->catSet();
for ($i = $tot; $i >= $bar; $i -= 1) {
<span>/*In this section I run through all of the items from the
gallery array and put them into handy variables then figure out
how I'm going to display them*/</span>
}
$DoIt->paginateMe();
$DoIt->catDisplay();
</code></pre>
</div>
</div>
<h4>Conclusion</h4>
<p>While this may not seem very complicated, or may seem more complicated then it needs to be, I used it as a learning experience. I built this to make the update process easier for me to handle and it does that quite well.</p>
<p>What you don't see here is the other half, and most useful part, of this, which is a custom built administration tool that I use to do the actual updating. I can add, edit, and delete items to the gallery with ease with that tool. I can even upload the appropriate photos. Pretty simple.</p>
<p>That's how I do it. Does it seem easy?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikemattner.com/2008/04/displaying-my-portfolio-pieces-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

