web design web development wordpress cms business blogs

A A A

WordCamp ABQ presentation: Build a powerful CMS with custom fields and custom post types

Author: ; Published: Sep 17, 2011; Category: Content Management System, Design/Development; Tags: , , ; No Comments

Slides from my presentation at WordCamp Albuquerque, Sep. 17, 2011. Also includes info about modifying Tiny MCE editor to make it more useful (and less dangerous).

The PDF is downloadable on Slideshare (link above slides and in the lower left of the control bar.)

What makes a good CMS?

Author: ; Published: Aug 16, 2011; Category: Content Management System; Tags: , , ; One Comment

In preparation for an upcoming presentation for WordCamp Albuquerque, I’ve been doing some thinking about what makes a good content management system. I was involved with providing content management systems for 6-7 years before I started using WordPress, so my perspective is not limited to my WordPress experience. I started using WordPress with some pretty high expectations about what a CMS should do, and I’ve been impressed with its ability to meet or surpass those expectations as I’ve learned more about how to configure it as a CMS.

This is not a feature comparison with other CMS platforms. Instead, I’m thinking about what the basic requirements for a CMS are, and what it takes for a CMS to be a good one. And there are only two kinds of CMS’s, from an end-user perspective: “good” or “bad.” Thinking about that inevitably leads to thinking about what kind of people use CMS’s (the “end users”), so I’ll start with them.

The people who update the company website don’t care what flavor the CMS is.

Typically, CMS users don’t maintain the website because they love websites. They maintain the website because it’s part of their job. For the most part, they want to make an update quickly and easily, and then go on to more important things. They don’t care if the CMS is WordPress, Joomla, Drupal or some other flavor, as long as it makes their work easier and quicker, and doesn’t get in their way. This may seem obvious, but I know from experience that a lot of developers don’t give this any thought.

Ease-of-use is not negotiable.

Complicated, confusing user interfaces are productivity killers. They can be a mere annoyance or an actual obstruction to keeping the website updated. When updating the website is difficult, the normal and usual end result is that the website does not get updated. And at that point, its value as a business and communication tool is non-existent. WordPress is famous for its ease-of-use and friendly user interface, consistently ranking ahead of other platforms in this regard. And it can be made more so, with a little bit of intelligent use of custom post types and custom fields.

The need for HTML coding must be minimized or eliminated.

This is actually an ease-of-use issue for most end users, but I think it deserves special mention. Straight out of the box, WordPress flunks this test. If all editing and formatting must be done in the WordPress editor, a good working knowledge of HTML (and possibly some CSS) is mandatory. But in the hands of a good developer, WordPress can excel in making HTML coding either optional or completely unnecessary.

Flexibility is critical.

Although there are some things most businesses and organizations need in a website, many of them also have some unique needs. A good CMS must be able to accommodate these needs without extensive and expensive development, while maintaining ease-of-use for the end user. With custom fields, custom post types, and custom taxonomies, WordPress is one of the most flexible platforms around.

The CMS platform must be well-supported.

Business users will not gamble on a system with an uncertain future or inadequate technical support, and why should they? In most cases, of course, the level of support an end user gets is dependent on the developer who implemented their website. But that developer can draw on the WordPress community when necessary. WordPress is the most widely used open-source CMS platform in the world by a very wide (and accelerating) margin. It has a large, committed developer base, in addition to the core development team. If there is a better bet than WordPress in terms of longevity, I’ve not heard of it.

Getting assistance as a developer from the WordPress community is practically standard procedure. Much of what I’ve learned about WordPress comes from WordPress’ excellent online documentation, and from other developers (most of whom I’ve never met in person) who are willing to offer assistance or advice.

In addition, should the original developer fall short in website support, finding a good WordPress developer is relatively easy: they’re not rare. Owners of WordPress-based websites do not need to fear that they’ll have to redo their website on yet another platform if they wish to work with a new developer.

Did I mention ease-of-use?

I just thought it was worth mentioning one more time ;-)

How to List Upcoming Events and Events Archive with Custom Post Types

Author: ; Published: Jun 27, 2011; Category: Content Management System, Design/Development, WordPress; Tags: , , ; 3 Comments

Recently, I had an opportunity to build an events listing that showed only upcoming events, with the next event appearing at the top. That’s pretty easy to accomplish. But I also wanted past events to disappear from the listing and show up instead on an events archive listing. It took a lot of searching and asking questions in two WordPress forums to piece together a query that worked.

First, I created a custom post type for events. Then I created a custom field called “order-date” to control ordering. Why a custom field? Why not rely on WordPress’ innate order-by-date function? Because WordPress uses the date posted, and it’s quite likely that events will not be posted in the order of their occurrence. But just as important, I needed the order-date to be the date of the event so we could use it to drop an event from the upcoming events listing and move it to the events archive listing. The custom field uses the Y-m-d date format for comparison with the Y-m-d format of today’s date.

Here is the query on the upcoming events listing template:

<?php
   $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $today = date('Y-m-d', strtotime('-6 hours')); //define “today” format; note timezone offset of -6 hours
      query_posts(array(
      'post_type' => 'events', //query “events”
      'posts_per_page' => 5,
      'paged' => $paged,
      'meta_key' => 'order-date',
      'orderby' => 'meta_value',
      'order' => 'ASC', //sort in ascending order
      'meta_query' => array(
         array(
         'key' => 'order-date',
         'meta-value' => $value, //value of “order-date” custom field
         'value' => $today, //value of “today”
         'compare' => '>=', //show events greater than or equal to today
         'type' => 'CHAR'
         )
      )
   ));
   if (have_posts()) :
   while (have_posts()) : the_post();
?>

On a separate template for displaying the archive listing, I made the following changes (highlighted in red) to display past events in descending order:

<?php
   $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $today = date('Y-m-d', strtotime('-6 hours'));
      query_posts(array(
      'post_type' => 'events',
      'posts_per_page' => 5,
      'paged' => $paged,
      'meta_key' => 'order-date',
      'orderby' => 'meta_value',
      'order' => 'DESC', //descending order
      'meta_query' => array(
         array(
         'key' => 'order-date',
         'meta-value' => $value,
         'value' => $today,
         'compare' => '<', //show events less than today (past)
         'type' => 'CHAR'
         )
      )
   ));
   if (have_posts()) :
   while (have_posts()) : the_post();
?>

Basic Custom Fields Technique to Enhance WordPress as a CMS

Author: ; Published: Mar 11, 2010; Category: CSS, Design/Development, PHP for Designers, WordPress; Tags: , , , ; No Comments

WordPress

This is not a new trick, and I certainly did not invent it. It’s been used before, but when I went searching for information about how to do it, it was hard to find. In fact, I finally had to ask a friend who is much better at PHP than I am to help me (I only recently learned to spell P-H-P). This is really basic stuff, but for a lot of us, basic is what we need to get on with our projects.

Sometimes, you need things to NOT appear on a page unless something else that goes with it appears on the page. This is a pretty basic capability for most CMS systems, but I had never done it with WordPress on a page-by-page basis.

Here’s the scenario. I wanted to add a highlighted note in the subnavigation area of my WordPress theme, Evo4 CMS, and I wanted it to be tied to the content of the page it appeared on. I hadn’t used custom fields much, but it seemed to me that was the way to go. Here is an example of the code I wanted to appear below the subnavigation items on the pages:

<div class="sub-note">
     <h5>Subnav Note Heading</h5>
     <p>Sed do eiusmod tempor incididunt velit esse cillum dolore
     duis aute irure dolor.</p>
</div>

Pretty simple, right? I decided that, for greater flexibility, my client would have to be responsible for the HTML formatting within the div (this particular client is capable), but I did not want them to be responsible for the div itself, as things can get ugly when someone forgets to close a div or attaches the wrong class to it. In the WordPress backend, on the page on which I wanted the note to appear, I created a custom field named “subnavnote” and added the value (same as above, but without the div):

<h5>Subnav Note Heading</h5>
<p>Sed do eiusmod tempor incididunt velit esse cillum dolore duis
aute irure dolor.</p>

On the page template in my theme (page.php), in the subnavigation column, I added the following:

<div class="sub-note">
<?php echo get_post_meta($post->'ID, 'subnavnote', true); ?>
</div>

Woohoo! That displayed the text from the custom field in the subnavigation area. But there was a problem: when I went to other pages, an empty “sub-note” div displayed (CSS specified padding and a background color for the div, which caused it to be visible even when empty). And that was definitely NOT something to yell “woohoo” about.

I needed a way to make the div appear on a page only if there was a value for “subnavnote.” No note, no need for the note container. This was where Googling left me high and dry, as I didn’t know the right terms to use, or how to ask the question so that I was able to find a usable answer. I have no doubt the answer was and is out there, but it remained outside my grasp.

After fiddling and failing with some PHP code snippets, I asked a friend who is a PHP coder for help. Here’s the solution she gave me:

<?php $subnavnote_value = get_post_meta($post->ID,
   'subnavnote', true); ?>
<?php echo ($subnavnote_value != '') ?
   "<div class='sub-note'>".$subnavnote_value."</div>" : ''; ?>

Basically, if there is no value for the custom field on a particular page, this code prevents the div that contains the custom field content from appearing. And if there is a value for the custom field, both the value and its container div appear on the page.

I would break down the code and explain it if I was competent to do so, but I’m not. I can see how it works, however, and have adapted it to other similar circumstances, which greatly increases my ability to use custom fields. I hope this solution is similarly useful for you.