Power Tips For WordPress Template Developers

Advertisement

With its latest releases, WordPress has extended its potential well beyond blogging, moving toward an advanced, robust and very powerful content management solution. By default, WordPress delivers a very lightweight, minimal system that offers only basic functionalities. But where the WordPress core falls short, there are a wealth of plug-ins that extend its limitations.

Plug-ins often offer simple solutions, but they are not always elegant solutions: in particular, they can add a noticable overhead, e.g. if they offer more functionality than needed. In fact, some general and frequently needed WordPress-functionalities can be added to the engine without bloated plugins, using the software itself.

This article presents 8 tips for WordPress template developers that address common CMS implementation challenges, with little to no plug-in dependence. These examples are written for WordPress 2.7+ and should also work in the latest WordPress-version.

You may be interested in the following related posts:

1. Associating pages with post categories

WordPress enables administrators to identify any page as the posts page: this is ideal for CMS implementations featuring a single news or blog feed. However, WordPress provides no simple, out-of-the-box mechanism to configure a site with multiple, independent feeds.

Here’s a common use case: a company wants a simple and casual blog, and a seperate and more formal feed for press releases inside their “About Us” section. Let’s list a few requirements mandated by a sample client seeking just that:

  • At no point should these two feeds be displayed as one.
  • Links to these feeds need to appear in page navigation.
  • The Press Release page needs to have static, maintainable content above its feed.
  • For SEO purposes, these feeds should have a page-like permalink structure: in other words, “mysite.com/category/press-releases” is unacceptable; the goal is “mysite.com/about-us/press-releases”.

The proposed sitemap

As is often the case, there are several approaches one can take. Major considerations used to guage the best approach include the number of standalone feed pages (one, in this case: Press Releases) and the necessity for a “primary” feed requiring multiple category support. For this example, let us assume that “Our Blog” does need to behave like a full featured blog with categories.

Preparing the site

This approach to “pages with single feeds” is built upon an association created between a page and a post category. The “primary” blog will simply be the “posts page” with a few template adjustments that will exclude posts from the “Press Releases” feed. To meet the SEO requirement for a logical and consistent URL structure, we will need to carefully configure and set permalinks.

  • In the “Reading” settings, ensure that the “Front page displays” option is set to “A static page”, and that the “Posts page” is set to “Our Blog”.
  • In the “Permalinks” settings for WordPress, ensure that “Custom Structure” is selected. The structure should be: /%category%/%postname%/.
  • In the page list, identify the the permalink (or slug) for the “About Us” page (using our example sitemap: let’s say “about-us”). Identify the slug for the Press Releases page (“press-releases”).
  • Two corresponding categories must be added: an “About Us” category with a matching permalink (“about-us”), and a “Press Releases” category with a matching permalink (“press-releases”) and its parent category set to “About Us”.
  • Create a post in the “Press Releases” category for testing purposes.

The proposed sitemap

Excluding a category from the blog page

To exclude a category from the main blog page (which shows all posts across categories), the post query used for the blog page template6 must be modified.

The WordPress codex outlines the solution7. Simply identify the category ID for the “Press Releases” category (hovering the mouse over the category name in the admin panel and looking at the URL in the status bar is an easy way to find the ID – let’s use 5 for the example), and insert the following code above the post loop:

query_posts("cat=-5");

Note that many templates also include a list of categories in the sidebar, recent post lists, and other components that may not exclude posts from the “press releases” category. These will also need to be modified to exclude the category; this is easily supported by most WordPress calls.

Enabling the individual feed page

The feed page will require a custom page template8. For this example, we named the template “Press Release Feed”, and used the generic “page.php” template as a starting point (copying it and renaming it “page_press.php”).

Since the requirements mandate static, editable page content above the feed, the first post loop – that drops in the page content – will be left as is. Below the code for page content output, another post query and loop will be executed. Once completed, the query should be reset using “wp_reset_query” so that items appearing after the loop – such as side navigation – can correctly reference information stored it the original page query.

The general framework for the code is below. The query posts documentation on the WordPress codex9 provides insight into great customization.

query_posts('category_name=Press Releases');
if ( have_posts() ) : while ( have_posts() ) : the_post();
  //post output goes here... index.php typically provides a good template
endwhile; endif;
wp_reset_query();

Of course, be certain to assign the “Press Releases” page the new template, in the page editor.

The devil is in the details

Depending on the characteristics of the individual site, many additional template customizations – beyond those outlined above – will probably be necessary. In particular, this “power tip” does not cover specific strategies for handling individual post views within these isolated feeds. At the high level, using conditional in_category10 checks within the “single.php” template (used for output of individual posts) should provide the foundation for customizing post views based on their category. If you are interested, a more detailed article may explore these strategies in greater detail (please let us know in the comments!).

Alternative Scenarios

Creating individual page templates for each standalone feed is an efficient solution for a site with only a couple of such feeds. There are, however, WordPress-powered sites like m62 visual communications11 that extend the idea of category and even tag association with pages much more deeply. m62 features dozens of pages associated with individual blog categories, parent categories, and tags, seamlessly mixed in with standard, “feed-less” pages. In these instances, a smarter solution would involve specialized templates that match tag and category permalinks against page permalinks to dynamically create associations.

This approach can also facilitate sites that require more than one “primary” (multi-category) blog, through the use of hierarchical categories / parent categories.

Again, if there is interest, a future article can discuss these methods in detail.

2. “Friendly” member only pages

Out-of-the-box, WordPress includes an option to designate any page or post as private. By default, these items do not show up in page or post lists (including navigation) and generate 404 errors when visited directly – unless the visitor is logged in. While utilitarian, more often than not, this is not ideal for usability.

Often times, sites intentionally make public visitors aware of pages or posts whose full content is only visible to members. A friendly message alerting visitors that they have reached a members-only page, with a prompt to log in, may be a better solution. Content-centric websites may tease the public with “above the fold” – or abbreviated – content for the entire audience, while enticing the visitor to log in or sign up to read the entire article.

Linedata's blog upsells with member exclusive content

This example offers a framework for these “hybrid” member / public pages using the latter scenario as an example. Content featured “above the fold” – or above the “more” seperator – will be visible to the general public. Content below the fold will only be available to members. In place of content below the fold, public visitors will be prompted to log in.

This approach to “hybrid” pages is built upon public, published pages with a custom field used to identify the page content as “member exclusive”.

  1. Create a page or post.
  2. Start with a paragraph or two visible to the general public.
  3. Insert the “more tag” at the end of the public content.
  4. Enter content visible only to logged in members below the more tag.
  5. Add a custom field named “member_content”. Set its value to 1.
  6. Publish the page with public visibility (the default).

Hybrid public / member content

The next step involves editing the applicable template files. Typically, this will be “page.php” (pages) and “single.php” (posts). Note that if these hybrid views will only apply to pages, a developer can create a “member content” page template as an alternative to using a custom field. Doing so will eliminate the need for the custom field check and alternative outputs inside the same template.

For this example, we shall assume that we created a post (not page) with member exclusive content. Therefore, we will need to edit “single.php”. Inside the template, find the the_content call used to drop in page and post content. Here’s what this often looks like before the changes:

the_content();

Here is the new code with the alternative “public” view:

if(!get_post_meta($post->ID, 'member_content', true) || is_user_logged_in()) {
    the_content('<p class="serif">Read the rest of this entry »</p>');
} else {
    global $more; // Declare global $more (before the loop).
    $more = 0;  // Set (inside the loop) to display content above the more tag.
    the_content(""); //pass empty string to avoid showing "more" link
    echo "<p><em>The complete article is only available to members. Please log in to read the article in its entirely.</em></p>";
}

Combine this with the next tip to include a login form that sends members right back to the current page or post.

3. Embedding a log-in form that returns to the current location

Sometimes, sending members to the standard WordPress login form is not ideal. It may, for instance, not be consistent with the look and feel a client is seeking. There may also be instances where embedding a login form in a page – as in tip 7 – offers superior usability compared to clicking a link for the login page.

Museums in the Park, powered by WordPress, has a custom log-in form for members.12

The code below drops the WordPress login form into the template, and sends the user back to the page they logged in from.

<?php if(!is_user_logged_in()) { ?>
  <form action="<?php echo wp_login_url(get_permalink()); ?>" method="post">
    <label for="log"><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" /> User</label><br />
    <label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
    <input type="submit" name="submit" value="Send" class="button" />
    <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
  </form>
<?php } ?>

Be aware of a pitfall of this easy-to-implement power tip: if the user fails to login with the proper credentials, the log-in error will appear on the standard WordPress login form. The visitor will, however, still be redirected back to the original page upon successful log-in.

4. Identifying the Top Level Page

The “top level page” is the highest level page within the current branch of the sitemap. For example, if you consider the page below, you’ll find that “Support & Resources”, “Finding Support”, and “Support for Patients” all share the top level page “Support & Resources”.

The top level page is Support and Resources

There are some relatively new plug-ins that make “section”, or “top level page” WordPress navigation a cinch, such as Simple Section Navigation13. However, there are plenty of instances (outside of navigation) where the template may need to be aware of the current top level page.

For instance, you many want to be able to style certain design elements, such as the navigation bar’s background image, depending on the currently chosen section. This can be achieved by checking the page ID of the top level page inside the header, and dropping in additional styles when the IDs for those top level pages were found.

Top level navigation changes its background image depending on the top level page14

Here is how it works. Although WordPress offers no built in call to determine the top level page, it can be found with a single line of code in the template:

$top_level = ($post->post_parent) ? end(get_post_ancestors($post)) : $post->ID;

Using a ternary conditional15, this line of code checks the value of $post->post_parent, which returns the current page’s parent page ID, if one exists. If the conditional is evaluated as “true” (as any positive integer will), than the current page has some “ancestory”; in other words, it is inside of a page hierarchy or branch in the sitemap. If the conditional fails, the page is either a top level page, or not in any page ancestory (i.e. a post on a site without a blog “page” assigned).

If the current page has ancestory, an array containing the hierarchy “above” the page (parents, grandparents, etc) can be retrieved using the get_post_ancestors function. The last value in the array that function returns is always the ID of the top level page. Jump right to the last value using PHP’s end function. If the conditional fails (no ancestory), the code simply grabs the current page ID.

Keep in mind that, in many instances, this information is only useful when WordPress is working with an actual page (as opposed to a post, 404 page, etc). Therefore, this function and code that uses the top_level variable, may need to be wrapped inside a check that confirms that WordPress is loading a page: see the is_page() function16.

5. Breadcrumb Navigation – without a plug-in

Example of a WordPress site with breadcrumb navigation

There are plenty of WordPress extensions that generate breadcrumb navigation17. But you can actually create custom breadcrumb navigation with only a handful of lines of code in the template, opening up greater control and, potentially, less overhead. This approach to breadcrumbs builds on the get_post_ancestors function discussed in tip #4.

This tip won’t review formatting of breadcrumbs; for this example, the breadcrumbs will be dropped in an unordered bullet list. As it happens, lists of links tend to be a good format for search engines, and you can format them almost any way you like.

To start with, here is a basic implemenation of breadcrumbs that only deals with pages and includes a breadcrumb for “home” (the front page of the site) at the beginning of the list. Depending on the design of a particular template, some checks may need to placed around this code. In this example, it will be assumed that this code will be placed in the header.php template file, that the crumbs should appear only on pages, and that it should not show up on the front page. The current page and front page link will also be assigned special CSS classes for styling purposes.

if (is_page() && !is_front_page()) {
   echo '<ul id="breadcrumbs">';
   echo '<li class="front_page"><a href="'.get_bloginfo('url').'">Home</a></li>';
   $post_ancestors = get_post_ancestors($post);
   if ($post_ancestors) {
      $post_ancestors = array_reverse($post_ancestors);
      foreach ($post_ancestors as $crumb)
          echo '<li><a href="'.get_permalink($crumb).'">'.get_the_title($crumb).'</a></li>';
   }
   echo '<li class="current"><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
   echo '</ul>';
}

If the WordPress implementation has a static front page and has been assigned a “blog” page, one might want to show the breadcrumb path to the blog page. This can be accomplished by adding is_home() to the conditional check at the top:

if ((is_page() && !is_front_page()) || is_home()) {
   ...

The next evolution of this code involves the inclusion of breadcrumbs for individual category archives as well as individual posts. Note that WordPress allows posts to be assigned to multiple categories; to avoid making our breadcrumb trail unweildly, the script will simply grab the first category assigned to the post. For the sake of simplicity, the example will be assumed that hierarchical categories are not in play.

if ((is_page() && !is_front_page()) || is_home() || is_category() || is_single()) {
   echo '<ul id="breadcrumbs">';
   echo '<li class="front_page"><a href="'.get_bloginfo('url').'">Home</a></li>';
   $post_ancestors = get_post_ancestors($post);
   if ($post_ancestors) {
      $post_ancestors = array_reverse($post_ancestors);
      foreach ($post_ancestors as $crumb)
          echo '<li><a href="'.get_permalink($crumb).'">'.get_the_title($crumb).'</a></li>';
   }
   if (is_category() || is_single()) {
      $category = get_the_category();
      echo '<li><a href="'.get_category_link($category[0]->cat_ID).'">'.$category[0]->cat_name.'</a></li>';
   }
   if (!is_category())
      echo '<li class="current"><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
   echo '</ul>';
}

There are many ways to extend the breadcrumb navigation further. For instance, a developer might want breadcrumbs for different types of archives (tags, months, etc), or may incorporate hierarchical categories. While this article won’t walk through every possible implementation, the samples above should provide you with a solid framework to work with.

6. Creating sidebar content elements

Many websites feature distinct sidebars with common elements represented throughout the site, such as section navigation, contact information, and special badges (i.e. “Follow us on Twitter”). It is also common for sites to feature more basic HTML blocks in the sidebar that are associated with a single page, or several pages that may or may not be tied together in any logical way.

Some content management systems enable the idea of multiple content blocks out of the box. For instance, CitySoft Community Enterprise18 allows the editor to select from a variety of page layouts, some of which include multiple blocks of content that can be edited independently. This is convenient for some, though it does have some limitations: (1) it can be hard to integrate the prefabbed layout blocks into unusual areas in the overall site template, and (2), reusing some of these content blocks for multiple pages is not possible (without some additional, complicated custom development).

Here’s how to implement reusable “sidebar elements” in WordPress. For the sake of simplicity, this example assumes that only one sidebar element can be assigned to a page.

Fundamentally, these sidebar elements will simply be pages. Although non-essential, it can be a good organizational practice to create a page called “sidebars” that will contain all of the sidebar pages. Be careful to exclude this page in top level navigation and any other page lists or sitemaps. Sidebar elements are then constructed as “private” pages (so they cannot be searched or viewed independently by general visitors), with the “sidebar” container page set as the parent page. The title of the sidebar page will be used for the title of the sidebar element.

Editing a sidebar on the left; on the front end on the right

Once the sidebar has been created, the editor will need the ID of the sidebar page. The easiest way to find this is by rolling over the page title in the admin page list, and looking for the “id” in the URL (typically in the statusbar).

To assign the sidebar to a page, a new custom field19 is assigned to the page that will hold the sidebar called “sidebar”. The value for this field is the page ID of the sidebar page.

Now, in the sidebar template file (or wherever the sidebar element should appear), some code is included that checks for the custom field, and – if found – drops in the referenced page. To make the process of dropping the sidebar page content a bit more simple, the example will use the light weight plug-in, Improved Include Page20. Here’s the code, which also drops “h2″ tags around the page title:

$sidebar_pg = get_post_meta($post->ID,'sidebar', true);
if (function_exists('iinclude_page') && $sidebar_pg) {
   include_page($sidebar_pg,'displayTitle=true&titleBefore=<h2>&titleAfter=</h2>

      &displayStyle=DT_FULL_CONTENT&allowStatus=publish,private');
}

7. Feature selected posts on the front page

Many CMS implementations feature some selected items from the blog feed on the home page, or even throughout the site in a sidebar or footer element. Content editors are, wisely, selective about what merits a front page mention. Here’s how to implement a selective blog feed that can be placed on a front page template or anywhere else in the design.

Featured news feed on front page21

A special category is needed to classify posts as “Featured”; a category named “Featured” or “Front Page” is a good convention. For the content editor, marking a post as “featured” is as simple as adding it to this category (remember: posts can have multiple categories). On the template side, the ID of the “featured” category will be needed. The easiest way to find the category ID is by rolling over the category “edit link” inside WordPress administration and noting the ID in the URL (typically in the status bar).

Using this ID (“4″ in the example), and the number of posts to feature on the home page (let’s say three), the following code will list the featured posts beginning with the recent ones.

echo "<h3>Featured Blog Posts</h3>";
echo "<ul>";
$feat_posts = get_posts('numberposts=4&category=71');
foreach ($feat_posts as $feat) {
   echo '<li><a href="'.get_permalink($feat->ID).'">'.$feat->post_title.'</a></li>';
}
echo "</ul>";

As with the other examples, this code can be extended in a number of ways. For example, the SGE Corporation22 front page features the excerpt for the most recent item. The excerpt can be manually entered in the “excerpt” field or pulled automatically (if none is provided) by grabbing a certain number of characters from the beginning of the post’s content.

8. Highlight current post’s category

WordPress page lists assign special classes to each item, including classes that indicate whether a page is the current page, a parent page, an ancestor page, and so forth. Category lists do assign a special class (current-cat) to appropriate list items when the user is browsing a category’s archive. Unfortunately, categories do not, by default, get this special class assigned to them when the user is on a post inside the category. However, one can override this default limitation by grabbing the current category ID and passing it to the wp_list_categories function.

$category = get_the_category();
wp_list_categories('current_category='.$category[0]->cat_ID);

Note that there is one significant downside to this approach – only some category can be passed to the list categories function. So if a post is assigned to multiple categories, only the first category will be highlighted. However, if a site has distinct categories (say a news feed and an editorial feed), this can help a template developer treat the category more like a page navigation item.

Related posts

You may be interested in the following related posts:

Footnotes

  1. 1 http://www.smashingmagazine.com/2009/06/10/10-useful-wordpress-loop-hacks/
  2. 2 http://www.smashingmagazine.com/2009/05/13/10-custom-fields-hacks-for-wordpress/
  3. 3 http://www.smashingmagazine.com/2009/03/04/15-useful-twitter-plugins-and-hacks-for-wordpress/
  4. 4 http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/
  5. 5 http://www.smashingmagazine.com/2009/05/18/100-amazing-free-wordpress-themes-for-2009/
  6. 6 http://codex.wordpress.org/Template_Hierarchy#Home_Page_display
  7. 7 http://codex.wordpress.org/Template_Tags/query_posts#Exclude_Categories_From_Your_Home_Page
  8. 8 http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
  9. 9 http://codex.wordpress.org/Template_Tags/query_posts
  10. 10 http://codex.wordpress.org/Function_Reference/in_category
  11. 11 http://www.m62.net
  12. 12 http://www.museumsinthepark.org/staff-area/
  13. 13 http://www.cmurrayconsulting.com/software/wordpress-simple-section-navigation/
  14. 14 http://www.sge-corp.com
  15. 15 http://www.addedbytes.com/php/ternary-conditionals/
  16. 16 http://codex.wordpress.org/Function_Reference/is_page
  17. 17 http://www.smashingmagazine.com/2009/03/17/breadcrumbs-in-web-design-examples-and-best-practices-2/
  18. 18 http://www.citysoft.com
  19. 19 http://codex.wordpress.org/Using_Custom_Fields
  20. 20 http://www.vtardia.com/improved-include-page/
  21. 21 http://www.sge-corp.com
  22. 22 http://www.sge-corp.com
  23. 23 http://www.smashingmagazine.com/2009/06/10/10-useful-wordpress-loop-hacks/
  24. 24 http://www.smashingmagazine.com/2009/05/13/10-custom-fields-hacks-for-wordpress/
  25. 25 http://www.smashingmagazine.com/2009/03/04/15-useful-twitter-plugins-and-hacks-for-wordpress/
  26. 26 http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/
  27. 27 http://www.smashingmagazine.com/2009/05/18/100-amazing-free-wordpress-themes-for-2009/

↑ Back to topShare on Twitter

Jacob M (Jake) Goldman is the owner of 10up LLC, a web development and strategy agency with a focus on making content management easy and fun. 10up's clients range from small local businesses to major WordPress.com VIP clients like TechCrunch. You can find his insights and development tips by following him on Twitter @jakemgold

Advertising

Note: Our rating-system has caused errors, so it's disabled at the moment. It will be back the moment the problem has been resolved. We're very sorry. Happy Holidays!

  1. 1

    Great post, Thanks

    • 2

      .. and this is before you even begin to explore plugins and code hacks.

      but probably the two most attractive features about using WP for content management:-

      – despite the sameness of most blogs out there, sites really can appear unique
      – the community. very hard to beat, very easy to get solutions.

      the downside is that web dev is too damn easy! more seriously, some superb CMSes like MODx may arguably be having their growth stunted a little.

  2. 3

    Wits its latest releases, WordPress has extended its potential well beyond blogging, moving toward an advanced, robust and very powerful content management solution

    .

    Already from the start I strongly disagree. I just ended a 5-day ordeal where WordPress wouldn’t import an XML file it itself created of several hundred pages, then kept tripping over itself using simple wp_insert_post functions, and then when I finally got all of my pages inserted into the DB (using my own coding) WordPress refused to show the “Edit Pages” screen (was completely blank) which I tracked down to an update_post_caches function. Now I’m back to CakePHP where I will stay for large sites. Even the WordPress community (and several other development forums) had either no response or no idea how to aid. Sad part is Google revealed this error has existed since 2005.

    WordPress has a LOOOOOONNNNNNGGGGGGGGGGG way to go before it becomes what you opened this article with.

  3. 4

    Nice tips, really useful.
    Wordpress, doesnt work with large websites, but if you develop a small website,use this blog platform, easy to learn and save develop time.

  4. 5

    Tim, stop being such a whiner and learn some PHP.

    Smashing, I love you for reading my mind at least once every week.

  5. 6

    Great post!
    As a matter of fact, i’m currently trying to set up wp as a CMS and will definately use some of your ideas!
    THX

  6. 7

    Yes, please do post more articles about sites using word press that use multi-feeds as described in both scenarios in Tip one.

  7. 8

    Tim: We had the same problem on a large site when importing a WordPress XML file until we switched hosting providers — turns out the original host’s claim of being WordPress-friendly was false.

    Haven’t had any problems since with WordPress or the new host.

  8. 9

    Some interesting items there – thanks for sharing with us.

  9. 10

    This kind of post almost makes me wish I would have developed my site with WordPress instead of Joomla. Still, I keep up with WordPress and track the development in case my next site may fit with it. Thanks!

  10. 11

    Just wanted to say thanks for an excellent post! You’ve addressed many of the biggest questions I have about the flexibility of using WordPress for a CMS.

    I’d love to see some information about developing widgets that would be very useful to clients. You seem to read my mind pretty well already, so I’ll let you decide which topics to cover!

  11. 12

    I myself didn’t find this post useful. But I still enjoyed reading a quality article, which I know others will find useful. (I hate other blogs)

  12. 13

    CMI Web Studio

    July 2, 2009 9:30 am

    Word Press is an amazing open source blogging platform… key word there is blogging. Until Word Press goes far beyond some plugins, they will never be a true CMS. I’ve tested all of their latest to see how far they’ve come, and they have a long way to go for me to ever abandon coding myself. The potential is there.

    A second thought… It’s incredibly easy to build your own content management system, and 99% of clients only want to update text and/or an image from time to time. If a PHP developer can’t muster a basic sql update via form and develop it in a matter of 10 minutes or less, then they need to brush up on some skills before diving into the developer world. Most CMSs out there are both bulky and cumbersome, and from a hiring perspective, I can always tell the quality of a coder on his reliance on them.

  13. 14

    Incredible tips! This got me really fired up! Thank you SM!

  14. 15

    Chris Robinson

    July 2, 2009 9:53 am

    Some nice tips, not sure I agree with 6 though why not make some custom widgets?

  15. 16

    Great post glad to see some more WordPress posts!

  16. 17

    Jean-Baptiste Jung

    July 2, 2009 10:48 am

    Great posts, some tips are very useful. Dugg and Tweeted!

  17. 18

    Great post :)

  18. 19

    dv,

    switch ($success){
    case “dv”:
    echo “do what losers do while throwing out childish names”;
    break;
    case “me”:
    echo “spend time making money with my skills”;
    break;
    }

  19. 20

    Simon Harlinghausen

    July 2, 2009 12:14 pm

    Another great wordpress article.
    Keep on going.

  20. 21

    Fanale Creative

    July 2, 2009 12:21 pm

    Great post guys.

    “If a PHP developer can’t muster a basic sql update via form and develop it in a matter of 10 minutes or less, then they need to brush up on some skills before diving into the developer world.”

    While I agree with that, an experienced WordPress developer can get a site up and running just as fast. We recently had a client that decided they wanted a CMS after their site was built. We installed and implemented WordPress in about 10 minutes. While it does take a bit of knowledge, I think a strong PHP developer can do some great things with WordPress, and we continually use this platform for medium to large sites.

    Thanks Smashing

  21. 22

    It’s great to see how people think about the back-end organization of a site. I can get the content organized as far as navigation/structure, but the practical implementation…well I wonder if I make it harder than it has to be. Would love more of this type of info — wordpress is not really intuitive for what should be pages/posts/categories/tags/conditional/includes etc on a non-blog site. Thank you!

  22. 23

    In Breadcrumb, you can add the page number with $page value.

  23. 24

    thanks smashing. #2 and 3 are what i’m looking for.

  24. 25

    Good post, thanks….

  25. 26

    I really like this post. Maybe SM can write article how to fix famous WP bugs in admin panel.

  26. 27

    @Tim: Jacob did say “moving towards”.

    And I agree that the latest release is a step towards wordpress as a CMS; but I agree with you that it has a ways to go yet.

    BTW I had a similar problem. I manually increased the timeout for the import script and that fixed everything. You do have to blitz the database before you start again though.

    @CMI Web Studio “It’s incredibly easy to build your own content management system, […] in 10 minutes or less.” This comment shows that you don’t really know what a CMS is and while I agree that it’s important to understand the fundamentals only the most inexperienced (and foolishly naive) coder has your view on code reuse.

  27. 28

    Tim,
    you should learn more advanced PHP and try to understand setup of your server (hosting).

  28. 29

    @Allen I know you don’t know me or my work, but i’ve built many Content Management Systems from scratch. Yes, full on, do anything you can possibly come up with or imagine, built completely from scratch systems. It’s not that hard my friend. After all, there’s only so many ways you can interact with a database… add, edit, delete, and view/sort. Dynamic content is like developer 101. A CMS is for non coders and lazy people, and the end product when people implement these types of “systems” is often poor and far from tailored to the client. Just look at this very article… “8 tips for WordPress template developers that address common CMS implementation challenges”… i.e. how to hack your way through the back door to something it’s not. My experience has been high end clients demand this kind of attention to detail, rather then throw a hacked to bits mass build solution to a problem. To each their own. Word Press is great for what it is… a blogging tool.

  29. 30

    My top tip: Use sandbox. The biggest hassle my company have had with wordpress installations is reconfiguring the layout. I find myself turning a lot of the settings off, but even then, the overall performance of wordpress seems laggy and bloated.

    Often there’s so much customisation to do I wonder if it wouldn’t be quicker to build some wordpress sites from scratch. I call for a lighter-weight blogging platform.

  30. 31

    About the learning PHP discussion:

    As a not already that perfect developer I learned a lot PHP by using WordPress and starting to create my own themes. So I guess anything you do is a learning process and if you can get some out of it, do it. Maybe I can code my own CMS from scratch in a few years. But by now, I’ll stay with WordPress.

  31. 32

    I commissioned the m62 website mentioned in the article. I’m not a web designer – just a client – so maybe I have a different view of things.

    One of the reasons we were keen to use something like WordPress, and not just have something built from scratch, or something proprietary, was to avoid vendor lock-in.

    When we posted our requirements on the WordPress jobs board, I got an absolute load of high-quality developers offering to help us. I know that if we need a new developer, we’ll be able to find one – as a lot of people understand WordPress and are comfortable with it.

    Using WordPress was also – comparatively – a cheap option. The core functionality was already built. The back-end WYSIWYG editor is very user-friendly, and already designed. Staff at our company are using the CMS with minimal training. Previous interfaces have been a disaster-zone, and the website has always ended up being the ‘property’ of just one or two staff, which we want to move away from. This way, more people take a hands-on approach.

    We didn’t have to compromise in any way (so far) in terms of what we wanted from our CMS. I described what I want to see happen in non-tech language, and Jake has managed to implement it. There’s not been a time where I’ve heard a “no, WordPress can’t do that”.

    m62.net is deployed in a company of non-tech people (well, we’re great at PowerPoint, but that’s not really the same), and editing and adding content isn’t an issue. I don’t think our website looks like a blog, but we do get a lot of the benefits of using WordPress, like good SEO and easy (enough) implementation of RSS feeds for categories of content and so on. Adding a new section to the site (page, category, post in that category) takes a couple of minutes. Even moving the order of sections in the menu takes about 30 seconds. For a non-technical person, this is brilliant – just what we wanted.

    We’ve also been able to make some clever use of tags alongside categories, so we can use categories to place all our posts within the overall site navigation hierarchy, and tags to create ‘cut across’ pages for our newsletter, and our ‘service type’ pages. It’s effortless, once it’s up and running, and if we launch a new service I won’t need a developer to do anything.

    I spent a lot of time trying to guess (basically) whether WordPress would be a sensible choice as a CMS. In every comments section I ever read, there were a load of people saying “use Joomla”, “WordPress is a blogging tool, don’t use it as a CMS” (and others saying WordPress was the best CMS out there). I’m glad I trusted my gut instinct – as we have a website that does what we wanted, at reasonable cost, with a decent upgrade path, and a community of developers I can go to if I need new functionality – so avoiding vendor lock-in.

    I’m sure there are alternatives that would have worked too, but WordPress has worked very well as a CMS for my company.

  32. 33

    @tim might be cause of the change of the editor. Fix the config. Should work! But I prefer to do it all on my own and developing my own cms for commercial useage.

  33. 34

    Thanks Smashing Magazine!

    This is exactly the type of article I’m looking for. I really enjoyed it. It was very well written, easy to follow and had great subject matter.

    I’d agree with others that more of this would be excellent!

  34. 35

    @tommex

    I love how fools like you and dv know what PHP skills I have better than I do. I thought I said I’d go back to writing my own apps with CakePHP – let me check…


    …yea, I did. What I love even more is how you and dv want to blast my “skills” yet offer no solutions or evidence of lack of skills whatsoever. Are you even aware of the issue I mentioned? Do you know anyting about the functions I mentioned? I doubt so since it’s undocumented in WordPress. Little hint…you can find it in the post file called from the query file. What directory? I’ll leave that do you.

    I would’ve suspected before you blasted me you may have inquired about where I was seeking help so you could, perhaps, go review the issue. Perhaps even offer an idea of how to fix it. Rather, you want to drop bombs. Perhaps it is your own PHP skills that are lacking…which is why you stick to WordPress?

    @Oliver

    It is absolutely not a config issue. It is not a server issue. It is a WordPress issue.

    @Allen

    If by “blitz” you mean clean out the entire database, reinstall WordPress, remove all plugins and themes and then run my import script – it doesn’t work.

    Did I mention that I even exported via WordPress, did the steps in the previous paragraph and then imported WordPress’ xml file and got tons of “this page already exists” errors?

    I get some of you love WordPress and would marry it if you could. But, accept the fact it is a blogging platform. It is not a CMS. Sorry to break your heart. I still use WordPress on two sites. But those sites require very little in addition to the basic functionality offered by WordPress.

    I’d hate to see what would happened if I told the Joomla community I preferred Zend or CakePHP…I feel like a thief around here..

  35. 36

    I hope ZenPhoto and WP gets together as I’ve been using both for my sights for a long period of time now and would love to see them work together, as ZP’s current selection of WP-plugins are not endorsed by WP. :’3

  36. 37

    Not sure why you want to hack WP to get a poor substitute CMS when you can have much better functionality out of the box with Joomla. I have never seen a “good” WP site that goes much beyond a blog, though I suppose if you want to hack away, it could be done. Our blogs are WP (for now) and our CMS sites are Joomla. Use the right tool for the job and your life will be easier.

  37. 38

    miami web design

    July 3, 2009 9:51 am

    Great post, Thanks.

  38. 39

    Just tried no. 6.
    The code in line 3 must be “iinclude_page” not “include_page”.

  39. 40

    After reading excellent post and all comments i think i can share few options that i like about wordpress
    – functions, you can do anything you want if you understand those, very good for php wp developers.
    – simplicity, no need to spent time for building cms and on other way only basic options are there, not like at joomla, that you spent all day to take control on template, last days i’m creating wp theme in one day :-)

    TIP1
    if you want to use many pages for queying categories you can do with custom field. Create custom field example cat_no for page and add just number like 5, 14, or any other id of category. In template you do query for cats on pages and just insert $cat_no. Ths is in short lines but wordpress have a lot of possibilities just you need idea and litle php. Exemple for this tip is

    TIP2
    Even more complex things you can do with posts, categories and pages, example is , custom filters for sorting, also querying id of post on page for single view to got some filters working here also.

    TIP3
    more complex list of products, wp with two languages example
    Coding is not so good becouse this is my first wp advanced site.

    Answer for any problem you can find by searching over internet, thats how i started using wp year ago and now i’m totaly adicted to simplicity of wp.
    If you are enough dedicated to work, after 6 months you will see results by using wp as cms.

    Tnx Smashing
    p.s. sorry for bad english

  40. 41

    Using your suggestions above I could have avoided using WordPress MU for a site I recently created which called for distinctive sections. MU is working fine for the site but it came with its own learning curve plus extra coding to make it do what I needed.

  41. 42

    Niraj Narkhede

    July 3, 2009 9:11 pm

    great artical … thanks

  42. 43

    Tim: try to increase the memory limit of the WordPress instance. I had the same problems (blank edit_page.php). File wp-settings.php, line:
    if ( !defined(‘WP_MEMORY_LIMIT’) )
    define(‘WP_MEMORY_LIMIT’, ’64M’);
    I’ve changed from 32M. You can set it as high as your servers allows. You can use php.ini as well, but it didn’t worked for me, so I’ve had to change wp-settings.php

  43. 44

    I have exported and imported multiple very large wp sites using the feature built into core. Tim, YOU DO need to increase the max execution time in php.ini. If all else fails, just download the db backup plugin for wordpress (google it), and then import the backup file using the mysql console instead of via the frontend. Quit whining and look for a solution. It is a shame you spent a whole week trying to export and import data, that is embarrassing and then, to say it is because of a bug that has existed since 2005….haha.

  44. 45

    Very useful article, and certainly adresses some of the things I wondered if and how they were possible with WP.
    Ok, let’s start implementing these techniques in new themes, yay !

    Tom.

  45. 46

    great post love it!!!!

  46. 47

    great post!

    i’m currently working on a wordpress theme which i would like to publish for free.
    is it not possible to exclude a category from the blog like this:
    query_posts(“cat=-portfolio”); instead of query_posts(“cat=-5″);

    this would be much easier to install when someone will use my theme. so he don’t have to edit the file for the category id. i can just tell that he has to create a category named “portfolio”…

    thx in advance for suggestions
    Tommy Holiday

  47. 48

    “Not sure why you want to hack WP to get a poor substitute CMS when you can have much better functionality out of the box with Joomla. I have never seen a “good” WP site that goes much beyond a blog, though I suppose if you want to hack away, it could be done. Our blogs are WP (for now) and our CMS sites are Joomla. Use the right tool for the job and your life will be easier.”

    You’re kidding, right? Joomla is a hot mess. Way too clogged up.

  48. 49

    Thanks for a great article. Your first point is exactly how I want my site to work. While I have already implemented it using similar techniques, there are others here that are worth implementing. Thanks.

  49. 50

    Very interesting article. WP has enormous potential. I wouldn’t like to compare WP and Joomla – they are very different and both have a learning curve; perhaps more so with Joomla.

  50. 51

    Thanks for the tips! I’m testing/learning WP 2.8 on my band’s site with hopes of using it for client work. Splitting categories for different pages is super helpful.

    Cheers,

    M

  51. 52

    I’d love more in-depth posts about the wordpress feed thing! (1. Associating pages with post categorie) :)

  52. 53

    You didn’t mention pagination in tip #1. An important part of every blog & I’m having trouble seeing how it is supported in a page template.

  53. 54

    Associating pages with post categories: Definitely interested in seeing more on this…

    Great info on the breadcrumb have already put that code into use :)

  54. 55

    Great tips!

    I’m particularly interested in tip 1). I’ve almost got it working but the main blog page’s next_posts_link navigation functionality now seems to be broken. It knows how many pages should exist, but keeps showing the same content (i.e. same 10 posts) on each page. How do you add this sort of category exclusion while allowing navigation between pages of posts on your blog page? (Apologies if I missed the reference to this on your page.)

  55. 56

    @Tim-
    Sounds like an issue with memory management rather than WordPress. There are hundreds of VERY large sites that use WordPress rather well.

  56. 57

    I would love to see some more examples of #6, “Creating sidebar content elements.” I’m building a site in which the client wants to have a different sidebar for many of the different pages. I’m imagining that the best way to do this would be to create a separate template for each of those different pages. Those templates then, instead of inserting the standard sidebar.php file, make a call to insert content from one of these hidden sidebar pages. that way the sidebar elements would be available to be edited by the client. Would that work?

  57. 58

    TIP #4 Identifying the Top Level Page

    I would like to see an nice example of this, I am using something of a hacked code but, if there is an easier template-only solution or with a simple functions.php edit, that would be ideal.

  58. 59

    Fantastic! It helped me a lot, but…
    Tip #4
    $top_level = ($post->post_parent) ? end(get_post_ancestors($post)) : $post->ID;
    I’m trying to get the post slug instead of the ID, so I replaced $post->ID with $post->post_name and it worked very well…but ONLY in parent pages! At child pages, it always returns the ID!
    What is hapenning?

  59. 60

    I would’ve suspected before you blasted me you may have inquired about where I was seeking help so you could, perhaps, go review the issue. Perhaps even offer an idea of how to fix it. drakfall gold, you want to drop bombs. Perhaps it is your own PHP skills that are lacking

  60. 61
  61. 62

    Great tips!! I have a question about the tip number 3 – login page. How can I keep all (login, custom register form) on my custom template. I see in the comments where it mentions if the user types the wrong info that it will go to the original wordpress login look and feel. I would like for it to stay within my custom template. I can do this by copying the code from the login php file into a custom page template, but if WP updates then I have to redo everything. Any tips/suggestions. p.s. I will have a custom register page also.

    Thanks in advance!

    m

  62. 63

    December 13, 2005 that allows users to both submit questions to be answered and answer questions asked by other users. ,

  63. 64

    Good article, but can you please add an index with clickable links? That would result in a good overview and quick-to-find sections.

  64. 65

    thanks for the useful knowledge.

  65. 66

    The trick #1 doesn’t seem to work on my wordpress 2.9.2…

    I have set up everything, but categories are posted under /categories/%category%/%postname%/ while the pages are under /pageName/. I don’t think I missed any steps, so could it be that this trick isn’t possible in the latest WordPress?

    Thank you for your help…

  66. 67

    I have just started designing a template for one of my client , this helps me a lot :-)

    • 68

      You ought to really take into csnoideration working on developing this blog into a serious authority on this market. You evidently have a grasp handle of the matters everyone is trying to find on this website in any case and you would definitely even earn a buck or two off of some advertisements. I would discover following recent subjects and raising the quantity of write ups you place up and I guarantee you’d start seeing some wonderful focused traffic within the close to future. Only a thought, good luck in whatever you do!

  67. 69

    My god your guys are life savers! I’ve spent hours on this site since I discovered it. Keep up the truly AMAZING work. Great post!

    Loy

  68. 70

    I don’t think I missed any steps, so could it be that this trick isn’t possible in the latest WordPress?

  69. 71

    Hi,

    Thank you so much for your work !!
    I was looking for crappy plugins unstable and you saved my life !

    Thank you !
    Take care

  70. 72

    You just saved my life with the mention of the Simple Section Navigation Widget; not to mention a few cool tricks that don’t require editing/updating functions PHP. Thanks!

  71. 73

    达誉盛(北京)传媒科技有限公司是一家现代化的传媒咨询、广告策划、网站设计、网络营销、网络品牌推广、电子商务一体化服务公司公司于2006年10月01日依 法登记注册,2006年12月1日正式宣布成立,我们有专业的网站推广团队,软文编写、新闻发布,专业外链团队。欢迎联系在线电话:零一零八六八六九零零零QQ: 一九六五四四八六四一贺经理
    通过8年的实践和市场经验,我们有专业的技术团队,能够满足不同客户的需求。

  72. 74

    Excellent! I have been looking for an advanced WordPress resource for so long, and now I have found it.

  73. 75

    Hey, I have a question about the featured posts. Is this different than: (pardon my code if not correct)

    foreach.... {

    Is it because of lack of the loop?
    I only ask because I am still learning the loop (and custom post types), and this looks similar. If you have time, could you explain, or point me to an explanation? Thank you so much. I am excited to have found this resource.

↑ Back to top