<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"><title>WordPress is not PHP</title><author><name>Matt Read</name></author><link rel="alternate" href="https://mattread.com/wordpress-is-not-php"/><link rel="edit" href="https://mattread.com/wordpress-is-not-php/atom"/><id>http://mattread.com/?p=193</id><updated>2008-04-19T23:57:01-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-02T14:50:25-04:00</app:edited><published>2005-04-21T17:47:55-04:00</published><category term="web-design"/><category term="wordpress"/><category term="web-applications"/><category term="articles"/><content type="html">&lt;p&gt;There have many concerns and question about the template system used in &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt;. Mostly the concerns are with n00bs and the complications of PHP. &#x201C;I want to change this and that, but don't know PHP&#x201D;. I hear this a lot. But the thing is, you don't need to know PHP to change the &lt;a href="http://codex.wordpress.org/Templates"&gt;Templates&lt;/a&gt; in &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt;. &lt;!--more--&gt;&lt;/p&gt;&#xD;
&#xD;
&lt;h2&gt;The Template System&lt;/h2&gt;&#xD;
&#xD;
&lt;p&gt;Lets' start with &#x201C;&lt;a href="http://codex.wordpress.org/The_Loop"&gt;the Loop&lt;/a&gt;&#x201D; as we call it. Probably the most confusing part of the &lt;a href="http://codex.wordpress.org/Templates"&gt;Template&lt;/a&gt; for a non-programmer. The Loop looks like this:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="highlight php"&gt;&#xD;
&lt;![CDATA[&#xD;
&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;&#xD;
&#xD;
	 //Template Section 1: post content Template Tags go here&#xD;
&#xD;
&lt;?php endwhile; else: ?&gt;;&#xD;
&#xD;
	//Template Section2: no posts found stuff here.&#xD;
&#xD;
&lt;?php endif; ?&gt;&#xD;
]]&gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;It may look complicated, but it's actually quite simple. In &lt;a href="#ex1"&gt;Template Section 1&lt;/a&gt;, all the posts information will be displayed. Within that section we will put all the posts &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt;, and our HTML to format them. In &lt;a href="#ex1"&gt;Template Section 2&lt;/a&gt;, we will display a message telling the user no posts were found, if we find none to meet their criteria. &lt;/p&gt;&#xD;
&#xD;
&lt;h3&gt;Template Section 1: The Posts&lt;/h3&gt;&#xD;
&#xD;
&lt;p&gt;We'll start with outputting the post tile. Simply add in the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt; &lt;code class="html"&gt;&amp;lt;?php the_title() ?&amp;gt;&lt;/code&gt;. That will output the title of the post. &lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Now let's output the date of the post. Simply add the date's &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt; &lt;code class="html"&gt;&amp;lt;?php the_date() ?&amp;gt;&lt;/code&gt;. That outputs the date of the post.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;We will also, of coarse, need the content of the actual post. Simply, again, add the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt; &lt;code class="html"&gt;&amp;lt;?php the_content() ?&amp;gt;&lt;/code&gt;.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Now let's put it all together with some HTML:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="highlight php"&gt;&#xD;
&lt;div class="post"&gt;&#xD;
	&lt;h2&gt; &lt;?php the_title() ?&gt; &lt;/h2&gt;&#xD;
	&lt;p&gt; &lt;?php the_date() ?&gt; &lt;/p&gt;&#xD;
&#xD;
	&lt;?php the_content() ?&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;And there's our simple template. Now let's add some more.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;First let's add a link to the post, permalink as it's called, on the title. We get the actual URL, something like &lt;code class="html"&gt;http://mysite.com/archives/2004/09/post-title/&lt;/code&gt;, with the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt; &lt;code class="html"&gt;&amp;lt;?php the_permalink() ?&amp;gt;&lt;/code&gt;. We will need to put that in our &lt;code class="html"&gt;&amp;lt;a href=&#x201D;&#x201D;&amp;gt;&lt;/code&gt; HTML tag.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;We also want to add in links to each page of our post, next page, previous page, etc.. We simply call another &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt;, &lt;code class="html"&gt;&amp;lt;?php link_pages('&amp;lt;p&amp;gt;','&amp;lt;/p&amp;gt;') ?&amp;gt;&lt;/code&gt;. Now here's another confusion people have. We've added in, what programmers would call, arguments to our &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt;. That is, we've added in &lt;code class="html"&gt;'&amp;lt;p&amp;gt;', '&amp;lt;/p&amp;gt;'&lt;/code&gt; to the brackets of the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tag&lt;/a&gt;. In this case we are just saying, if there are pages to link, output the page links with a &lt;code class="html"&gt;&amp;lt;p&amp;gt;&lt;/code&gt; at the start, and a &lt;code class="html"&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; at the end. Hence, enclosing it all in HTML paragraph tags. Most &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt; have different arguments you can pass to them, causing them to format their output differently.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Now let's add in our new tags.&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="highlight php"&gt;&#xD;
&lt;![CDATA[&#xD;
&lt;div class=&#x201D;post&#x201D;&gt;&#xD;
  &lt;h2&gt; &lt;a href=&#x201D;&lt;?php the_permalink() ?&gt;&#x201D;&gt; &lt;?php the_title() ?&gt; &lt;/a&gt; &lt;/h2&gt;&#xD;
  &lt;p&gt; &lt;?php the_date() ?&gt; &lt;/p&gt;&#xD;
&#xD;
  &lt;?php the_content() ?&gt;&#xD;
&#xD;
  &lt;?php link_pages('&lt;p&gt;','&lt;/p&gt;') ?&gt;&#xD;
&lt;/div&gt;&#xD;
]]&gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;Now we have a fully functional Posts section, &lt;a href="#ex1"&gt;Template Section 1&lt;/a&gt;. Let's move on to &lt;a href="#ex1"&gt;Template Section 2&lt;/a&gt;.&lt;/p&gt;&#xD;
&#xD;
&lt;h3&gt;Template Section 2: No Posts Found&lt;/h3&gt;&#xD;
&#xD;
&lt;p&gt;For our &lt;a href="#ex1"&gt;Template Section 2&lt;/a&gt;, the no post found section, all we need to do is put in a message to tell the user nothing was found, to meet their criteria. Whether it was a search or a mis-typed URL. So let's use the following simple HTML:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="highlight html"&gt;&#xD;
&lt;![CDATA[&#xD;
&lt;p&gt;Sorry, no posts could be found to match your criteria.&lt;/p&gt;&#xD;
]]&gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;Now let's put it all together.&lt;/p&gt;&#xD;
&#xD;
&lt;h3&gt;Complete Template&lt;/h3&gt;&#xD;
&#xD;
&lt;p&gt;Putting all we learned above together, we get a nice simple &lt;a href="http://codex.wordpress.org/The_Loop"&gt;Loop&lt;/a&gt; &lt;a href="http://codex.wordpress.org/Templates"&gt;Template&lt;/a&gt;.&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="highlight php"&gt;&#xD;
&lt;![CDATA[&#xD;
&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;&#xD;
&#xD;
	&lt;div class=&#x201D;post&#x201D;&gt;&#xD;
		&lt;h2&gt; &lt;a href=&#x201D;&lt;?php the_permalink() ?&gt;&#x201D;&gt; &lt;?php the_title() ?&gt; &lt;/a&gt; &lt;/h2&gt;&#xD;
		&lt;p&gt; &lt;?php the_date() ?&gt; &lt;/p&gt;&#xD;
&#xD;
		&lt;?php the_content() ?&gt;&#xD;
&#xD;
		&lt;?php link_pages('&lt;p&gt;','&lt;/p&gt;') ?&gt;&#xD;
	&lt;/div&gt;&#xD;
&#xD;
&lt;?php endwhile; else: ?&gt;&#xD;
&#xD;
	&lt;p&gt;Sorry, no posts could be found to match your criteria.&lt;/p&gt;&#xD;
&#xD;
&lt;?php endif; ?&gt;&#xD;
]]&gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;As you can see, we have done no PHP coding, just some simple HTML with &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; Template Tags added in.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Obviously this is not a complete template, as we have no header and footer containing all the &lt;code class="html"&gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;body&amp;gt;&lt;/code&gt; tags. But with some simple HTML and more &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt;, and no PHP, we can easily add all that is needed for a complete HTML document. That's right, an HTML document, not a PHP script.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;As we can see &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; is not PHP. &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; is powered by PHP, but uses a simple template system, easily modified by even the most novice of users. None of that complicated Perl code like MT has ... Yes, believe it or not, MT is also powered by a complicated programming language. The only difference is marketing. MT has been marketed as having simple templates with no programming skills needed. However, somehow, and I don't know why, &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; has gotten a rap of being complicated and only for the hardcore programmers out there. But as we can see, using the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt; is extremely easy and requires no knowledge of PHP at all.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Changing the format and style of your &lt;a href="http://codex.wordpress.org/Templates"&gt;Template&lt;/a&gt; is as easy as using a little HTML, CSS and Template Tags. Just like other Weblog systems out there. &lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;However, as with any software, there is room for improvement.&lt;/p&gt;&#xD;
&#xD;
&lt;h2&gt;Improving Templates&lt;/h2&gt;&#xD;
&#xD;
&lt;p&gt;One of the problems with the &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; &lt;a href="http://codex.wordpress.org/Templates"&gt;Template System&lt;/a&gt;, in my opinion, is the default &lt;a href="http://codex.wordpress.org/Templates"&gt;Template&lt;/a&gt;, or theme, itself. Specifically the sidebar, with all the &lt;code class="html"&gt;is_*()&lt;/code&gt; functions. We shouldn't expect a novice &lt;a href="http://wordpress.org"&gt;WordPress&lt;/a&gt; user to understand what these functions mean. I would suggest removing all the &lt;code class="html"&gt;if(is_*())&lt;/code&gt; statements in place of a simple sidebar with just the essentials. Say, Search, Pages, Archives, Categories, Links, Meta information and take out all the complicated if statements and includes.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Another problem I see with the default &lt;a href="http://codex.wordpress.org/Templates"&gt;Template&lt;/a&gt; is the CSS in the header. I think all CSS should be contained in the style sheets themselves. Again remove the if statements. When a user wants to modify the CSS it seems logical to have just the simple CSS in one place, to easily modify.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Another problem I see is with some of the &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt;. Such as &lt;code class="html"&gt;&amp;lt;?php bloginfo() ?&amp;gt;&lt;/code&gt;. Instead of having one function to display some necessary information, like blog name, description, url, etc., why not have specific tags for the highly used information. Like say, &lt;code class="html"&gt;&amp;lt;?php blog_name() ?&amp;gt;&lt;/code&gt;, &lt;code class="html"&gt;&amp;lt;?php blog_description() ?&amp;gt;&lt;/code&gt;, &lt;code class="html"&gt;&amp;lt;?php blog_url() ?&amp;gt;&lt;/code&gt;, etc., to maintain consistency. For some of the less used information, charset, version, etc., the &lt;code class="html"&gt;&amp;lt;?php bloginfo() ?&amp;gt;&lt;/code&gt; tag would be fine.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;And some of the other advanced &lt;a href="http://codex.wordpress.org/Template_Tags"&gt;Template Tags&lt;/a&gt; in use in the default &lt;a href="http://codex.wordpress.org/Templates"&gt;Templates&lt;/a&gt;, like &lt;code class="html"&gt;&amp;lt;?php list_cats(0, '', 'name', 'asc', '', 1, 0, 1, 1, 1, 1, 0,'','','','','') ?&amp;gt;&lt;/code&gt;, should be simplified to not contain all those arguments. Maybe use &lt;code class="html"&gt;&amp;lt;?php wp_list_cats() ?&amp;gt;&lt;/code&gt; where all those settings would be set in the admin area.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;It would also be nice to try to simplify the loop, although I can't see any way of doing that now, to use as little actual PHP, like if else statements, as possible. Also take out the else, for when no posts are found, and always use the 404 template file.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;The point I'm trying making is to take the PHP out of the &lt;a href="http://codex.wordpress.org/Templates"&gt;Templates&lt;/a&gt;, as much as possible, so users don't get confused and think they need PHP skills to modify the &lt;a href="http://codex.wordpress.org/Templates"&gt;Templates&lt;/a&gt;.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Those are just my thoughts on the matter.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;If you need any help with your templates, or would like to learn more about the monkey, I'd be glad to help out. Just &lt;a href="/contact/"&gt;drop me a line&lt;/a&gt;.&lt;/p&gt;&#xD;
</content></entry>
