Two weeks ago we published the first part of this article, covering multiple column content techniques and associating pages with post content; we discussed how to use the “More”-tag, hide standalone categories from the category list and retain the page layout for post views within a category page. This article presents the second part of the article; it covers customizing basic content administration and adding features to the post and page editor in WordPress. You would like to see more similar articles in the future? Let us know in the comments to this post!
Many template developers have learned the art of making beautiful, highly customized front end templates for WordPress. But the real wizards know how to tailor the WordPress administrative console to create a tailored, customized experience for content managers. The dashboard is the first screen presented to registered visitors when they visit WordPress administration (/wp-admin). Tailoring the dashboard to a client can be the difference between a great first impression and a confused one, particularly if the theme customizes the administrative experience.
Two weeks ago we published the first part of this article, covering multiple column content techniques and associating pages with post content; we discussed how to use the “More”-tag, hide standalone categories from the category list and retain the page layout for post views within a category page. This article presents the second part of the article; it covers customizing basic content administration and adding features to the post and page editor in WordPress. You would like to see more similar articles in the future? Let us know in the comments to this post!
Customizing Basic Content Administration
Many template developers have learned the art of making beautiful, highly customized front end templates for WordPress. But the real wizards know how to tailor the WordPress administrative console to create a tailored, customized experience for content managers.
Customizing the Dashboard Widgets
The dashboard is the first screen presented to registered visitors when they visit WordPress administration (/wp-admin). Tailoring the dashboard to a client can be the difference between a great first impression and a confused one, particularly if the theme customizes the administrative experience.
The dashboard is comprised of a number of widgets that can be repositioned and toggled using the “screen options” tab. WordPress has a hook – wp_dashboard_setup – that can be used to customize the dashboard widgets, as well as a function – wp_add_dashboard_widget – that allows developers to easily add new widgets.
Here is a practical use case based on that documentation: let’s remove all of the default widgets that don’t pertain to managing a typical site, and add one simple widget that welcomes the administrator and reminds them how to contact the developer for support.
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
wp_add_dashboard_widget('custom_help_widget', 'Help and Support', 'custom_dashboard_help');
}
function custom_dashboard_help() {
echo '<p>Welcome to your custom theme! Need help? Contact the developer <a href="http://mytemplates.com">here</a>.</p>';
}
Customizing the Contextual Help Dropdown
Throughout its administrative panel, WordPress has a small “Help” tab just below the administrative header. Clicking this tab rolls down contextual help for the current administrative page.
If your theme has some special functionality that might not be intuitive, it’s a good practice to add some additional contextual help. For example purposes, let’s assume that the theme has been customized to use the “more divider” to separate content into two columns, as described in the first tip. That’s probably not an obvious feature for your average content editor. To accomplish this, hook the contextual help text when on the “new page” and “edit page” administrative pages, and add a note about that feature.
//hook loading of new page and edit page screens
add_action('load-page-new.php','add_custom_help_page');
add_action('load-page.php','add_custom_help_page');
function add_custom_help_page() {
//the contextual help filter
add_filter('contextual_help','custom_page_help');
}
function custom_page_help($help) {
//keep the existing help copy
echo $help;
//add some new copy
echo "<h5>Custom Features</h5>";
echo "<p>Content placed above the more divider will appear in column 1. Content placed below the divider will appear in column 2.</p>";
}
Dropping in Your Own Logo
Providing the client some administrative branding can be quick and easy. Here’s how to replace the default WordPress “W” logo in the administrative header with a custom alternative.
First, create an image that fits the allocated space. As of WordPress 2.8, the logo is a 30 pixels wide and 31 pixels tall transparent GIF. When using a transparent GIF or 8-bit PNG, ensure that the image matte matches the header background color: hex value 464646.
A logo named “custom_logo.gif” inside the template directory’s image subfolder can substitute the default WordPress logo with the following code inside the theme’s “functions.php” file.
Basic contributors might be confused or distracted by some of the boxes that surround the page or post editor, particularly if there are a handful of plug-ins that have added their own meta boxes. Alternatively, the content editor might simply want to keep author and contributor hands off of some special fields or features.
Let’s say the content editor wants to keep authors and contributors way from the “custom fields” box. We can use the “remove_meta_box” function – regardless of user role – to remove that from all post editing screens like so:
//hook the admin init
add_action('admin_init','customize_meta_boxes');
function customize_meta_boxes() {
remove_meta_box('postcustom','post','normal');
}
The “remove_meta_box” function takes three parameters. The first is the ID of the box. The easiest way to discover the ID of the meta box is to look for the ID attribute of the corresponding DIV “postbox” in the source code. The second parameter determines which the context the function applies to: page, post, or link. Finally, the context attribute determines the position within its context: normal, or advanced (in most cases, just setting this to “normal” will work fine).
The next step is to extend the “customize_meta_boxes” function so that the “custom fields” box – ID “postcustom” – is only hidden from users with author role or lower. We’ll use get_currentuserinfo to retrieve the user level. According to the WordPress codex, authors represent level 2.
//hook the admin init
add_action('admin_init','customize_meta_boxes');
function customize_meta_boxes() {
//retrieve current user info
global $current_user;
get_currentuserinfo();
//if current user level is less than 3, remove the postcustom meta box
if ($current_user->user_level < 3)
remove_meta_box('postcustom','post','normal');
}
Adding Features to the Post & Page Editor
WordPress provides a “custom fields” box that makes it quick and easy to start adding new metadata to your pages and posts. For a tech-savvy client or low budget customization, this is a great, inexpensive method to start adding some unique fields for a custom implementation.
But there are plenty of times when something more specialized than a generic “custom fields” box may be appropriate. A less savvy client may be confused by the generic fields that lack any documentation. A checkbox for a Boolean field may be more intuitive for a client than instructions to choose the custom field name from a drop down and type in “1” or “true” under the value. column Or maybe the field should be limited, in select box like fashion, to a few different choices.
The WordPress API can be used to add custom meta boxes to pages and / or posts. And with WordPress 2.8, adding new, tag-like taxonomies is a cinch.
Adding a Custom Meta Box
Let’s say a hyper-local journalist has hired us to build a news blog that covers politics in New York City. The journalist has a few writers on her team, none of whom are particularly tech-savvy, but they will all be set up as authors and posting their reports directly in WordPress. Our imaginary client wants each article associated with a single borough, in addition to a “city-wide” option. Articles will never be associated with 2 boroughs, and the staff is prone to typos.
A developer accustomed to basic WordPress administrative customization would probably go to “categories” first. Make a “city-wide” category, with sub-categories for each borough. However, categories are multi-select, and there’s no obvious way to prevent authors from selecting several. Furthermore, the client wants the borough named at the beginning of the article, and if categories are used in other ways (like news topics), extracting the borough name would be a bit tricky.
So how about a “custom field” for “borough”? The authors never remember to look in that generic custom fields box, and in their rush to meet deadlines, occassionally spell the borough wrong, breaking the “filter by borough” feature on the front end.
Let’s apply the code discussed in the codex to this use case, assuming we want the “Borough” field to only appear on posts (not pages), and be shown on the top-right of the post editor page.
/* Use the admin_menu action to define the custom boxes */
add_action('admin_menu', 'nyc_boroughs_add_custom_box');
/* Adds a custom section to the "side" of the post edit screen */
function nyc_boroughs_add_custom_box() {
add_meta_box('nyc_boroughs', 'Applicable Borough', 'nyc_boroughs_custom_box', 'post', 'side', 'high');
}
/* prints the custom field in the new custom post section */
function nyc_boroughs_custom_box() {
//get post meta value
global $post;
$custom = get_post_meta($post->ID,'_nyc_borough',true);
// use nonce for verification
echo '<input type="hidden" name="nyc_boroughs_noncename" id="nyc_boroughs_noncename" value="'.wp_create_nonce('nyc-boroughs').'" />';
// The actual fields for data entry
echo '<label for="nyc_borough">Borough</label>';
echo '<select name="nyc_borough" id="nyc_borough" size="1">';
//lets create an array of boroughs to loop through
$boroughs = array('Manhattan','Brooklyn','Queens','The Bronx','Staten Island');
foreach ($boroughs as $borough) {
echo '<option value="'.$borough.'"';
if ($custom == $borough) echo ' selected="selected"';
echo '>'.$borough.'</option>';
}
echo "</select>";
}
/* use save_post action to handle data entered */
add_action('save_post', 'nyc_boroughs_save_postdata');
/* when the post is saved, save the custom data */
function nyc_boroughs_save_postdata($post_id) {
// verify this with nonce because save_post can be triggered at other times
if (!wp_verify_nonce($_POST['nyc_boroughs_noncename'], 'nyc-boroughs')) return $post_id;
// do not save if this is an auto save routine
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
$nyc_borough = $_POST['nyc_borough'];
update_post_meta($post_id, '_nyc_borough', $nyc_borough);
}
Take another look at the second to last line in that code block, where the post metadata is updated (update_post_meta will also add the meta if it does not exist). That function stores the field key and value (second and third parameters), assigned to the designated post (first parameter) in the same generic “way” that custom fields are stored. Notice that the field key name was prefaced with an underscore: “_nyc_borough”. Meta fields with keys beginning with an underscore are not shown in the generic “custom fields” box. All other meta fields are shown in that box.
We can use this field value in our template just as we would embed generic custom fields.
A taxonomy, generically defined, is a “classification.” Post tags and categories in WordPress are both types of taxonomies, one of which – categories – has a “hierarchical” proprietary: categories can have child and parent categories. The ability to define new taxonomies has actually been around in some basic form since WordPress 2.3 – but WordPress 2.8 ups the ante, making it incredibly easy for template developers to add and manage tag-like taxonomies.
At the core API level, taxonomies may be hierarchical (or not, a la “tags”) , associated with pages or posts, and have a few other more esoteric properties related to allowing post queries and permalink structures. The potential for custom taxonomies is considerable – posts could easily have two types of categories, pages could have multiple tags, and sites could have multiple tag clouds based on groupings more specific that a generic “tag.”
While the architecture for all of this is all there, the real magic of custom taxonomies – introduced in 2.8 – has only been enabled for posts and non-hierarchical types. But if those qualifications aren’t a show stopper, a developer can get a lot of value out of just a few lines of code: a new tag-like meta box added to posts, a new “posts menu” option for managing those values, and the ability to easily output clouds, filter by taxonomies, design taxonomy templates, and do just about anything one could do with generic “tags” on the front end.
Let’s go back to that hyper-local New York City politics blog. Say the editor wants authors to be able to “tag” articles with a distinct “people” taxonomy, but still wants to retain generic tagging. The new “people” taxonomy will highlight the names of political leaders mentioned in articles. On the front end the editor envisions a “tag cloud” that will help the most active politicians get recognized (for better or worse!). Clicking on a leader’s name in the cloud should bring up a list of articles “tagged” with the given politician.
The following few lines of code will add the new “people” meta box to posts and add a new option to the “posts” menu where the taxonomy values can be managed.
//hook into the init action to add the taxonomy
add_action( 'init', 'create_nyc_people_taxonomy');
//create nyc people taxonomy
function create_nyc_people_taxonomy() {
register_taxonomy('people', 'post', array('hierarchical' => false, 'label' => 'people'));
}
To output a cloud for this custom taxonomy highlighting the 40 most-tagged politicians, the generic “wp_tag_cloud” function can be used with a few parameters.
Clicking on a person’s name will automatically take the visitor to an archive for that taxonomy. Custom template files can also be built for the custom taxonomy. A “taxonomy.php” template file in the theme folder can be used for all custom taxonomies. A “taxonomy-people.php” template file could be used for the “people” taxonomy in the example. As with all archives, if no taxonomy-specific template files are available, WordPress will fall back to the generic “archive” and “index” template files.
Further Reading on Custom Meta Boxes and Taxonomies
Back in July, “Power Tips for WordPress Template Developers” presented 8 basic techniques for adding popular features to the front end of a WordPress-powered website. The premise was that WordPress has become an elegant, lightweight content management solution that offers the fundamentals out of the box, atop a modular core that offers incredible potential in the hands of a capable developer.
WordPress does not try to be an “everything to everyone” CMS right out of the box. Many systems do an average job incorporating 99% of what the potential CMS market might need, even if the last 15-20% is used only by a fraction of the market and adds considerably to the system’s overall “heft” (or bloat). At the other end of the spectrum are completely custom solutions that are finely tailored to exact needs, at the cost of reinventing wheels like polished content editing with media management and version control.
That previous “Power Tips” entry scratched the surface, covering a handful of API calls mixed in with some simple PHP code and configuration tips intended to help beginner WordPress template developers kick their game up a notch. This article takes power tips to the next level, expanding on some of the topics in the first article, and introducing more advanced techniques and methods for customizing not only the front end, but the content management (or back end) experience.
Back in July, “Power Tips for WordPress Template Developers” presented 8 basic techniques for adding popular features to the front end of a WordPress-powered website. The premise was that WordPress has become an elegant, lightweight content management solution that offers the fundamentals out of the box, atop a modular core that offers incredible potential in the hands of a capable developer.
WordPress does not try to be an “everything to everyone” CMS right out of the box. Many systems do an average job incorporating 99% of what the potential CMS market might need, even if the last 15-20% is used only by a fraction of the market and adds considerably to the system’s overall “heft” (or bloat). At the other end of the spectrum are completely custom solutions that are finely tailored to exact needs, at the cost of reinventing wheels like polished content editing with media management and version control.
The self-proclaimed WordPress “code poets” have, alternatively, focused on doing an A+ job with the “fat middle”: the 80-85% of features that almost everyone needs, and coupling those with a first rate framework and API that enables capable developers to add in almost any niche or “long tail” feature. In fact, the core WordPress framework is so capable that a handful of “intermediary” frameworks that sit on top of it have already emerged.
That previous “Power Tips” entry scratched the surface, covering a handful of API calls mixed in with some simple PHP code and configuration tips intended to help beginner WordPress template developers kick their game up a notch. This article takes power tips to the next level, expanding on some of the topics in the first article, and introducing more advanced techniques and methods for customizing not only the front end, but the content management (or back end) experience.
You may be interested in the following related posts:
The average blog or website has a single, clearly defined block of space for a given page’s or post’s unique content. But there are plenty of creative websites that don’t conform to this simple notion of “one unique block” per page. A creative online portfolio layout might feature a screenshot and project description in a left column, and a list of technologies used in a right column. Both the left and right column are unique to each portfolio page.
Here’s a screenshot from an in-development website project, built on WordPress. The “projects” area features portfolio-like layouts of green building projects throughout the state. In addition to a specially designed gallery visualization, note that the individual project profile has two distinct columns.
A more commonplace layout might feature an obvious, primary block of page content, but also feature a sidebar element that is unique to the current page: maybe a quote from a customer about a specific product or service. The “Power Tips” article offered a method to associate sidebar elements with multiple pages using custom fields and page IDs (tip #6). That approach isn’t very effective or efficient for designs with a 1:1 relationship between sidebars and pages (where each page has a unique sidebar element).
Yes, the developer could add table buttons to the WordPress editor, and let content authors fend for themselves: a solution prone to problematic layouts and bad output relied upon far too often. Here are a few simple options that keep layout in the hands of the template developer while making content management easier and problem-free.
Short, simple, and HTML free? No worries.
Before we delve into solutions that assume a need for HTML formatting in this second content block, let’s review a more basic solution. If the second column does not need to be formatted – or maybe should not be formatted by the editor for design reasons – then a simple custom field will do the trick. In the case of a simple sidebar element, like a customer quote, this may be just the trick.
There are already great tutorials and useful custom fields hacks that walk through the WordPress custom fields feature, so if you are not familiar with the basic idea behind custom fields, start there. Let’s go ahead and create a custom field named “sidebar_content” (also known as the “key”), and put some simple content in there. Just to shake things up, let’s assume we do need a very basic HTML feature for our content authors, who know nothing about HTML: line and paragraph breaks. Let’s also assume that we want to format this sidebar content on the front end with some of the basic automatic niceties we get when we output post content, like curly quotation marks.
Here’s how we can output this in any template file, using the “the_content” filter to apply the WordPress content filter to our custom field. That filter converts single line breaks to break tags, double line breaks to paragraphing tags, and even transforms simple quotation marks to curly quotes!
Of course, we can make this even more intuitive for the content authors by creating a new meta field box for sidebar content instead of relying on the generic “custom fields” box… which will be covered later in this article!
Using the More Tag for… More
The WordPress editor has a button “more tag” button that is primarily intended to separate “above the fold” content from “below the fold” content. If you are not already familiar with the “more” divider, read up on that first.
If the pages or posts that need a two column layouts also rely on traditional more separation, this tip will most likely not be effective, unless one of the columns is also the intended “above the fold” content. However, most instances where a two column layout is desirable don’t overlap with a traditional above / below the fold need. It is fairly rare, for instance, for pages (vs. posts) to actually make any use of the more tag. So let’s start taking advantage of that feature!
The basic idea is that content above the more divider will represent one block of HTML content, while content below the divider will represent a second block (be it a sidebar element or column).
Here is how to retrieve content above and below the more divider as separate blocks of HTML content in the corresponding page template file.
The global “more” variable lets WordPress know whether or not the content is being rendered in an “above the fold” (or “teaser”) only view. By passing an empty string to “the_content”, we prevent a “read more” link from showing up below the HTML content. And, for column two, we pass a second parameter to “the_content” – true – which instructs WordPress to output the content without the teaser.
If the intent is to output the second block of content outside of the loop in another template element, such as a sidebar, this approach is a bit trickier. One option would be to store the second block of content in a uniquely named variable, declare it as a global variable in the sidebar, and – if there is any content inside the variable – output a new block. An alternative could involve checking which page template is in use with the “is_page_template” function, and, if the two column template is in use, calling “the_content” with the second parameter set to true, as in the example above.
The Plug-in Solution: Adding a Second HTML Content Block to the Editor
The ideal solution, of course, might be a second HTML editor field on the WordPress page or post editor. Unfortunately, no such plug-in existed… until recently! While writing this article, we decided it was time such a solution did exist, and so the author of this article is happy to present a free, open source plug-in that combines some savvy understanding of how TinyMCE works (hint: it’s as simple as a class name) with the custom meta box tutorial covered later in this article, and a little bit of extra customization and polish thrown into the mix.
Secondary HTML Content adds a second HTML editor to pages, posts, or both (customizable with a simple settings panel). You can output the content in a sidebar with an included widget, or integrate it more tightly with the template by using “the_content_2″ and “get_the_content_2″ functions.
Associating Pages with Post Content: Reloaded
“Power Tips” covered the basic foundation for associating different WordPress pages with different post categories. The basic premise was that many sites require, effectively, different post “feeds” on different pages. For instance, there may be a company blog, but there may also be an independent news feed.
This continuation offers specific tips that extend the core concept introduced in part 1, making it easier to have multiple page / category associations, preventing entrance into the “real” category archive, and ensuring that individual post views retain a visual and architectural association with their parent “category page” layout.
A Review of the Basics & the Two Fundamental Approaches
At the heart of the category / page association (covered in part one) was:
A matching of the “page slug” with the “category slug.”
Using “query_posts” and the category parameter to exclude standalone page categories from the primary feed
Using a dedicated page template with “query_posts” and the “category name” parameter to create a page featuring a feed for a single category.
Before delving into the tips that extend those ideas, it is important to make a distinction between two common but fundamentally different use cases for page / category association. The more typical use case, which the first part was tailored to, is a website that has a primary feed, like a blog, but also has one or two distinct feeds, most often for a formal news or press feed.
The second use case is a bit more esoteric: there is no primary feed. The site has many pages, and many (but not all) of those top level pages are individual feeds of posts. The example, at the end of this power tip, m62.net, is one such use case. Another common use case might be – again – a portfolio centric website.
Let’s say we want to create “Joe’s Portfolio”, and Joe wants to feature 4 distinct areas of expertise. Each area of expertise should be a top level page, say, joes-portfolio.com/web-design, joes-portfolio.com/graphic-design, etc. Joe wants to have a little write-up about each service area at the top of the page, followed by a feed of case studies. Why a feed instead of sub-pages? Maybe Joe wants prospects to be able to subscribe to an RSS feed for each area of expertise; maybe he wants to easily cross-tag case studies based on industry; maybe he plans to update frequently and doesn’t want a huge page sitemap or wants visitors to page through a date-organized collection of case studies. There are many reasons to use posts instead of pages.
The following tips provide solutions for both use cases.
Automatically Determining the Page / Category Association
Part one suggested that a unique page template be created for any page associated with a category. That page template would then query for posts using a hardcoded category name or category ID. If there are only one or two standalone “category pages”, this is an efficient and effective solution.
However, if there are many page / category associations, as in use case #2 (no primary feed), the process of manually creating page templates for each association is tedious to build and maintain, and not realistic if content editors who don’t program need to be able to create more page / category associations on demand.
An alternative would be to create a generic page template, let’s say “template-category-connector.php”, that is assigned to all pages associated with a category, and automatically determines the right category to query.
The following code performs the matching and executes the post query. The magic happens by taking advantage of our matching page and category slugs. Once again, if the website does not use permalinks, an alternative approach will be required (one permalink-free alternative could involve a custom field with the associated category ID).
That’s all there is to it… just proceed on with the post loop to output the applicable category’s posts. Note that the template should probably check for an actual return value from line 1, and output a graceful error in the event there is no match.
Handling Entry into the “Real” Category Archive
Now that there is a dedicated page layout that handles the category feed, we will want to be make certain that the visitor doesn’t land on WordPress’ default category “archive” view. For instance, when using permalinks with the default “category base” value, the archive view for a category with a top level category assigned a “web-design” slug would be: mysiteurl.com/category/web-design. However, the intent is for visitors to view this category at our top level page: mysiteurl.com/web-design.
By combining the WordPress category template file with some smart redirects, we can prevent entry into the default category archive. Out of the box, the WordPress template system allows developers to create global category archive templates as well as templates for individual category archives.
If we are in use case #1 – a site with a traditional blogfeed and a standalone news feed on a “press releases” page – we will want to use the latter solution. Let’s say, as in part one, the category ID for “press releases” is 5. We create a template file in our theme folder named category-5.php. Under use case #2 (no primary feed), we will want to redirect all category archive traffic, in which case we need to work with the category.php template file.
A few lines of code in either template file will redirect visitors to the right place. We’ll also pass HTTP error / redirect code “301″ – which will tell search engines to permanently redirect their link to the right location. Note that this particular code assumes we are using a permalink configuration. Line 2 can be modified to accomodate that situation.
In effect, that code removes the category base (”/category” by default) from the overall relative URL, and safely redirects the visitor to the page with the matching slug. Of course, if the site falls under use case #1 (one or two stand alone feeds), the line three could dropped into a specific category template (i.e. category-5.php) with a hardcoded absolute URL for the redirect destitation.
Hiding Standalone Categories from the Category List & Primary Site Feed
In the first use case (only isolating one or two categories from a primary feed), it may be necessary to prevent isolated categories or the posts within those categories from appearing in some common theme elements that would traditionally include them.
Consider the example from part one: a site with a traditional blog and a standalone press release feed. Assume the owners of the site want the RSS feed for the blog to be persistently available throughout the site (typically manifesting itself as an RSS icon in the browser location bar), but don’t want the press release items included in that primary feed. By default, the WordPress primary feed is available at “/feed”, and includes all published posts, regardless of category or any other post property.
To exclude categories from the primary RSS feed, we need to filter the WordPress function that retrieves the posts. Let’s again assume that the category ID for Press Releases is 5. The following code should be placed in the template’s “functions.php” file.
add_filter('pre_get_posts','exclude_press');
function exclude_press($query) {
if($query->is_feed && !$query->is_category) $query->set('cat','-5');
}
To summarize, we use the “pre_get_posts” filter to modify the post query before it executes. Within a new filter – named “exclude_press” – a conditional confirms that the post query is for a feed, and that the query is not for an individual category. If the check pans out, the query is modified to exclude category 5 before execution.
The notion of globally filtering the post query may have broader implications depending on the site’s unique requirements. With some smart conditional checking, the filter could be extended to prevent the category from appearing anywhere except within the category or isolated post view. But be careful when extending the filter, and be sure to consider all possible views, including administrative views!
However, if the categories widget is in use, or the category list is used throughout the template, an alternative approach is required. Enter the “list_terms_exclusions” filter. Again, the following code should be placed in the “functions.php” template file.
add_filter('list_terms_exclusions', 'filter_press');
function filter_press($exclusions) {
$exclusions .= " AND t.term_id != 5 ";
return $exclusions;
}
The return value of a “terms exclusions” filter is tacked onto the “where” clause in the SQL query that retrieves the terms. Without digging too deep here, the reason for discussing “terms” as opposed to, say, “categories” is because WordPress abstracts a variety of different taxonomies (link categories, post categories, tags, custom taxonomies, etc) into a unified database model that handles all taxonomies. Calls to “get categories”, “get tags”, and so forth, are all referring back to general “terms” behind the scenes. Ever wonder why category, tag, and other IDs tend to jump around? They are all being added to the same table. Assuming a fairly clean install, try adding a new post category, and note the ID. Then add a tag, and note its ID… one greater than the new post category.
Retaining the Page Layout for Post Views within a Category Page
One of the most common challenges to tackle with page / category association is retaining a sense that the visitor is still within the “category page” hierarchy – and not a global feed hierarchy – when a visitor is reading an individual post. Part one hinted at this challenge under “The devil is in the details,” and started to suggest a path that incorporated using the “in_category” function. We will explain how to use “in_category” within templates, as well as how to trick functions that reference the original query object into thinking that they are “within” the category page.
Let’s start with case #1, and building on the example in the first article, assume we only need to contend with one isolated feed, “Press Releases” (category ID 5).
Say the theme has a sidebar template that lists post categories when rendering the blog part of the site, and when rendering a standalone page, shows a page list instead. Here’s an extremely simplified version of what that might look inside the sidebar template file.
if (is_page())
{
wp_list_pages();
}
else
{
wp_list_categories();
}
Of course, there may be alternative widget sets for pages or posts, and there is likely to be more than just one element in the sidebar. But the concept should hold. Now going back to the example, the theme should render posts in category 5 (Press Releases) as if the visitor were on a page (not the blog). Leveraging the “in_category” check, the code above would now like the following:
Note that if there are multiple categories whose posts should resemble page output, the “in_category” function should be passed an array of IDs, like so:
in_category(array(5,7));
The need for a “in category” check is probably moot in case #2 (multiple page/category associations, without a primary feed): the template is probably structured to output the same elements on pages and posts from the get go. In other words, everything is handled as if it is a page since there is no primary feed. However, the following tip – that dynamically looks up the faux parent page ID (the page associated with the category) – is necessary for the next part of this tip. Just amend the code to check if “faux_parent_page” has a valid value: if it does, then the post is inside an isolated category associated with a page.
Once again, this approach to dynamically seeking the faux parent page (the category page) depends on taking advantage of the matching permalink structure between post categories and pages that is at the heart of this association. If the site is unable to use permalinks, a more complex alternative look up of the faux parent page will be necessary.
Now that we have the ID of the category’s associated page, we can trick “black box” theme elements that determine page or post properties on their own (by referencing the post query) into thinking they are actually working with the category page.
The most common use case is page navigation. Whether its breadcrumbs, a top level page menu that should retain “current” (on) states, or a side navigation menu that should display the current section, there are many “black box” navigation functions that need to be tricked into rendering themselves as if on the category page.
Let’s use a simple top level page list, which should maintain proper “current_page”, “current_page_parent” (and so on) classes when on a post under a category page. Here’s what that simple function might look like before our changes:
wp_list_pages('depth=1');
Of course, posts do not normally have parent pages, so there will be no “current” classes assigned to that output when reading a post. Here is how to trick that function into thinking it is rendering the navigation for the “parent” category page.
//retrieve faux parent page dynamically… can skip and hard code in case 1
foreach(get_the_category() as $category) {
$faux_parent_path = '/'.get_category_parents($category, FALSE, '/', TRUE);
}
$faux_parent_page = get_page_by_path($faux_parent_path)->ID;
//reset the post query as if on the faux parent page
query_posts('page_id='.$faux_parent_page);
//execute our "faked out" function
wp_list_pages('depth=1');
//reset the query back to the initial state
wp_reset_query();
If there are multiple elements that need be “tricked,” a best practice would be to put the “faux parent page” retriever at the top of the template, and declare it a global in any template files that need it. This would avoid repeated look ups of the faux parent page.
An Example: Seeing it All Put Together
A great example of a WordPress-powered CMS that pushes use case #2 to its limits can be seen at the home of m62 visual communications, at http://www.m62.net.
All of the navigation items across the top (Presentation Theory, PowerPoint Slides, etc) are pages associated with post categories. The sub-navigation on the right contains sub-pages that are also associated with sub-categories. For example, in the screenshot above (available here), the visitor is on the “Pharmaceutical Templates” page (faux category), which is a child of the “PowerPoint Templates” page (also a faux category). The content starting with “Download free” (below the page title) is the content from the “Pharmaceutical Templates” page. The posts below the “Next Steps” bar, titled “Latest in Pharmaceutical Templates”, are the posts inside that category. The applicable related category is automatically discovered by the WordPress template, populating the category name “Latest in X” and recent posts. Now let’s look at one of the posts inside that category.
Using the tips outlined above, the individual post retains the feel of being within the “Pharmaceutical Templates” page, right down to the breadcrumb navigation and “current” states in the navigation.
But not only does m62.net use category / page associations for most top and second level navigation items, it actually extends the concept to tags. The 5 “tabs” on the top right actually represent post tags, and each has a “tag page.”
Stay tuned!
The second part of the post will be published here, on Smashing Magazine, in two weeks. Hence, you may want to subscribe to our RSS-feed and follow us on Twitter. Any ideas or suggestions? Comment on this article!
You do not have to be able to design or code if you want to use WordPress, that’s the beauty of it. Anyone can grab a domain, get a theme and start blogging. If you want to separate your blogs theme from the other thousands that exist in a crowded niche, then paying a small amount for a premium WordPress theme can be a very rewarding for you in the long term.
Here are Ten Stunningly Fresh WordPress Themes From November 2009, enjoy!
You do not have to be able to design or code if you want to use WordPress, that’s the beauty of it. Anyone can grab a domain, get a theme and start blogging. If you want to separate your blogs theme from the other thousands that exist in a crowded niche, then paying a small amount for a premium WordPress theme can be a very rewarding for you in the long term.
Here are Ten Stunningly Fresh WordPress Themes From November 2009, enjoy!
This theme is a complete WordPress Theme, designed from the ground up with custom fields, functions. This theme is built to function first and foremost as a news/folio/business, then it can be used for just about any site that needs a beautiful layout.
Network WP – $30
Network WP is a WordPress template inspired by big TV network sites. It is packed full of features including featured slider, image resizing to fit in with the template, social bookmarking, threaded comments, breadcrumb, JQuery efftects, widget ready.
Marketplace is a both clean and stylish WordPress theme with the intent and focus on creating a community site for industry news, tutorials, etc. This theme includes many popular built in features seen in today’s industry leading community sites. This themes comes with 5 different color options to choose from.
If you’ve ever thought about starting a community based site, then this is your theme. Purchase today and be up and running in no time at all. Themes features include: Advertisement Slots, Tabbed Sidebar Navigation, Flickr Group Integration, Post Images, Clean Comments, Social Links, RSS For Posts and Comments, and many more.
Headlines continues where our old magazine themes left off. It has tons of requested features like featured area, social bookmarks, author highlighting, flexible layout to name a few. It’s the perfect platform to launch your magazine or blog and reach out to the world!
Manilla is a 4 in 1 WordPress theme that was designed to be a simple to use platform for your personal portfolio, as well as, working blog. After getting your site setup your new homepage will be populated with the most recent projects from your work section and queried with an AJAX carousel.
This theme is a Portfolio and / or a Corporate template for companies, portfolios, webdesigners, eBooks sites, etc, to showcase your services and work. This theme comes with CU3ER a brand new 3D slidereasy to customize, IMaxell also has an added 2 more sliders for your customization, s3Slider and jQuery innerFade.
Designed especially for online shops The Furniture Store features a plugin free localized ecommerce system, a membership area, creating and saving a wishlist, an informative customer service area, unique “Shop by…” widgets, lots of independent widget ready areas and sooo much more!
London Creative + comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider and PrettyPhoto plugin (better clone of Lightbox).
High quality free Wordpress Themes have become harder and harder to find in the past year, with the influx of premium themes, more and more designers and developers are selling themes (and rightly so, they do amazing work). However, the quality of freely available themes has improved as well; in fact, some themes are very advanced and professional and can serve as a solid foundation for your next designs.
There are a lot of choices out there for someone wanting to choose a Wordpress theme for their blog. But, that aside, the quality is certainly there, and we are sure you will be impressed with this Wordpress theme compilation.
You may be interested in the following related posts:
High quality free Wordpress Themes have become harder and harder to find in the past year, with the influx of premium themes, more and more designers and developers are selling themes (and rightly so, they do amazing work). However, the quality of freely available themes has improved as well; in fact, some themes are very advanced and professional and can serve as a solid foundation for your next designs.
There are a lot of choices out there for someone wanting to choose a Wordpress theme for their blog. But, that aside, the quality is certainly there, and we are sure you will be impressed with this Wordpress theme compilation.
You may be interested in the following related posts:
AppCloud Theme A nice e-commerce WordPress theme with a clean and professional look. Built upon 960.gs, with an integrated slideshow, two layouts (horizontal and vertical) for app/gadget images. The theme also includes sections “Featured products” and “Top Selling” and a categorized products view.
Berita (via ThemeCloset) Berita is a minimalist corporate theme created for companies to prominently display their logo, but the theme could be used for any type of website. It’s a feature-rich theme with a preview slider on the front page and a robust theme administration page.
Magazeen Magazeen is a two-column theme released specifically for Smashing Magazine readers. The theme has some subtle enhancements that encourage looking at related and new posts, like a related posts drop-down effect for the category link.
Mainstream Theme (via Wootheme) You have the option of choosing from five different theme colors with Mainstream. Thumbnails are automatically resided and the sidebar is widgetized.
Rusty Grunge Rusty Grunge is a simple WordPress theme yet still gives you the “destroyed” look. This theme utilizes a fully-widgetized sidebar and has been downloaded over 28,000 times and is featured as a pre-installed theme on Dreamhost’s default installation of WordPress.
Obscure WordPress Theme A dark magazine WordPress theme suitable for any site niche; also a good fit for a community-based site.
Paper Wall Smashing Magazine released the illustrated theme Paper Wall last month. The inspiration behind the Paper Wall theme was a designer’s desk, as designers typically put things on paper. It’s a two-column theme with many elements of paper: paper boards, peeling paper and paper “menus”.
Gallery WordPress Theme a beautiful, free, gallery-style Thematic child theme for WordPress, designed by Christopher Wallace especially for Smashing Magazine and its readers. It is extremely flexible and can be used as a starting point for design galleries and portfolios.
Cool Retro A nice, clean illustrated WordPress theme with a retro-look and nice typography.
Life Collage Life Collage is a child theme of the Hybrid theme framework. It’s about getting back to the roots of blogging. About sharing our lives. And, about having a little fun while we do it.
Shalom Typo This theme was designed for the typographic template contest at Smashing Magazine by the German designer David Hellmann. This WordPress theme is based upon this layout. A clean and nice typographic WordPress-theme.
Jungleland Theme (via Theme Lab) The stylish browns give an earthy feel to this blog making it a good choice for those blogs focused on the environment and nature. It features a photo gallery and a sidebar menu
Folio Elements Theme (via Press 75) With its black background, Folio Elements theme will surely make your images and photographs noticed. There is no sidebar, no widgets, no list of categories, no place to comment and nowhere to search. However, if you are looking for a basic carousel-type theme with absolutely no basics, bells or whistles, then Folio Elements might be the one for you.
SimpleCart(js) SimpleCart(js) is another child of the Thematic Wordpress framework. The theme requires WP E-Commerce and is a flexible way to showcase products with the grid framework. The theme features a rich wood background and simple white content area.
Glassic A simple clean WordPress theme with the focus on typography and simplicity. Released by Abdullah Ibrahim exclusively for Smashing Magazine and its readers.
Zinepress Theme (via Well Medicatedi) Zinepress is a two column magazine style theme. There is a nice sidebar with enough space for ads and for your widgets. It is hand coded and has valid XHTML STrict 1.0 and CSS Level 2.1. The developer has successfully tested this them with IE 6.0+, Firefox 2+, Opera 9+, Safari 3+, and Chrome 0.2+. Suggested Wordpress version is 2.7 or higher.
Futurosity Vero (via Theme Meme) Built on Sandbox and Blueprint CSS framework, the Futurosity Vero is a minimalist theme. Near the top of your home page, your most recent and featured post will be displayed.
PolaroidPress (via Tutorial9) PolaroidPress, as you might guess from the name, plays on the usage of “polaroids” in the theme that display your random images. It’s a simple two-column theme with an airy feel.
H5 The H5 theme is more of a proof-of-concept theme to show designers how to show theme designers how to design with HTML5 and CSS 2.1. It’s a bare-bones theme that’s perfect as a building block for creating your next Wordpress theme.
Inuit (via CSS Reflex) Inuit makes use of a lot of whitespace and preview images for each post on the homepage. The theme also comes integrated with Twitter and Flickr.
Wu Wei Clean, modern and minimal. The theme was based on the Taoist concept of wu wei: knowing when to act, and knowing when not to act. The theme is built on the principles of the grid system.
Cardeo Minimal A minimal three-column theme with plenty of white space and gray text.
Album Theme (by Allan Cole) Auto-focus is a blog theme designed for photographers to showcase their work.
Mystique (by Digital Nature) This sleek one column theme has a flexible-width, threaded comments, and an adjustable header.
Manifest Manifest is a straight-forward one column blog. It has no widgets or sidebar, but gives you a nice clean approach that focuses on your content.
Debug Theme (by Joost de Valk) When your WordPress installs fail and you need more information, the debug theme is perfect. On the home page, it displays the important URL’s, editor, memory setting, etc. On sub pages it shows the page type, all the query vars that are set and the SQL query for that particular page.
Portfolio Theme (via WPESP) Portfolio is a two column blog theme which can be described as a minimalist. This modifiable design will make your own portfolio look great!
Blog Theme The Carrington Blog-style theme is filled with advanced features like widgetized sidebars, AJAX loading of content, stylish galleries, customizable headers and colors.
Mobile Theme (via Carrington Themesl) The Carrington Mobile has a beautiful design supporting advanced touch browsers (Android, BlackBerry, iPhone and Pre).
Pyrmont V2 Theme (via WP) Pyrmont V2 is a two-column theme with a black background that could very well make your photographs and designs stand out.
Destyle Theme Destyle is a magazine-style WordPress theme. This is another theme packed with useful features such as: multi-level superfish dropdown menu, ad management, predefined CSS styles, customa page templates, Twitter and Flick badges on sidebar and automatic image resizing.
ImpreZZ A dark, three-column theme that gives the second column a third dimension.
Would you like to see more similar lists on SM?
Your opinion is very important to us. There are literally hundreds of similar lists on various design blogs. We are trying to do our best to present you only the best of the best, collecting useful links over months. Would you like to see more similar lists in the future? Or should we drop lists altogether and focus on more original content?
We love our readers. We respect the hard work of designers and developers across the globe. And we do our best to make the web design community stronger and the Web a little bit prettier. Therefore we ask talented artists and creative professionals to showcase their skills and release something unique and beautiful as a gift to the community. And when designers agree, impressive works see the light of day.
Today we are glad to release Glassical — a free professional Wordpress-theme created by Abdullah Ibrahim. This theme was designed with the main focus being on typography, clean look and simplicity. Hopefully, you will be able to use it in your projects or at least use it as a foundation for your next projects. The theme is released especially for Smashing Magazine and its readers.
We love our readers. We respect the hard work of designers and developers across the globe. And we do our best to make the web design community stronger and the Web a little bit prettier. Therefore we ask talented artists and creative professionals to showcase their skills and release something unique and beautiful as a gift to the community. And when designers agree, impressive works see the light of day.
Today we are glad to release Glassical — a free professional Wordpress-theme created by Abdullah Ibrahim. This theme was designed with the main focus being on typography, clean look and simplicity. Hopefully, you will be able to use it in your projects or at least use it as a foundation for your next projects. The theme is released especially for Smashing Magazine and its readers.
Download the theme for free!
The theme is released under GPL. You can use it for all your projects for free and without any restrictions. Please link to this article if you would like to spread the word. You may modify the theme as you wish. The theme supports the WordPress 2.8 nested comment system and it is also customized for the WP Pagenavi plugin. Also, Cufón is used for embedding the Nevis font into the theme.
There are litterally hundreds of thousands of Word Press themes floating around on the web, I wanted to showcase some that didnt suck and and really highlighted what can be done in the “Free” theme niche. I specificly looked for themes that were well structured, clean and elegant. I hope you enjoy some of these themes and visit the respective sites.
There are litterally hundreds of thousands of Word Press themes floating around on the web, I wanted to showcase some that didnt suck and and really highlighted what can be done in the “Free” theme niche. I specificly looked for themes that were well structured, clean and elegant. I hope you enjoy some of these themes and visit the respective sites.
The Sky Was Blue
A lovely clean Word Press theme called “The Sky Was Blue”. This Word Press theme was built using the 960 grid system, it comes packed with JQuery effects, contact form and Twitter integration.
RockStar
A bold well structured design, called RockStar. This Word Press theme would be perfect for a personal blog, made by WOO Themes, you will get great support and Word Press tips from their site.
Colourise
This Word Press theme is called Colourise, it provides a great foundation layout on which you can add to in the future. A great example of this Word Press theme being used on a professional design blog is at http://www.psdvault.com/.
Selecta
This Word Press theme is a bold and bright video blog style design, it slightly reminds me of the Vimeo design. I love how the centerpiece of the design is the video, it really grabs your attention.
Magazeen
I really am surprised this Word Press theme is FREE, it is a high quality design and build and is packed to the brim with “out the box” features.
Elegent Designs Simplistic 4
Whilst this Word Press Theme does not immediately grab your attention with fluffy, bouncy graphics it does provide a solid layout for you to design on in the future. The layout is well structured and flows very well.
The Morning After
I particularly likethe black and white minimalism of this Word Press Theme, “The Morning After” provides a slick and clean blog layout.
WPESP Professional Word Press Theme
This Word Press theme would provide a great theme for a design or photography portfolio. It has a JQuery content slider and I am again in shock that this is a free theme.
Notepad Chaos
A very colorful and vibrant design, what more can I say !
Infinity
A lovely use of images, gradients and transparencies in web design, the Word Press theme ticks all the boxes for the creative design somewhere in you !
Assuming you have filled your blog with rich unique content, then maybe you should have a review of your on site SEO if you have not already done so.
There are many WordPress plug-ins to help you easily optimize your WordPress blog for search engines, if you want to increase your search engine ranking then these plugins will certainly help push your blog in the “Upward direction”.
Assuming you have filled your blog with rich unique content, then maybe you should have a review of your on site SEO if you have not already done so.
There are many WordPress plug-ins to help you easily optimize your WordPress blog for search engines, if you want to increase your search engine ranking then these plugins will certainly help push your blog in the “Upward direction”.
A personal favorite of mine, this plugin allows you to control and optimize your blog for search engines. It will give you control of all your meta data for each post, or you can set it to work automatically and auto generate your metadata.
This WordPress plugin is pretty simple it creates a compliant XML-Sitemap of your WordPress blog. When you add a post, page or edit existing content it will automatically update the sitemap.
This plugin will replace the standard WordPress links widget, it will give you full control over your outbound links within the SEO blogroll widget. You will be able to control link numbers and apply rel=”nofollow” attribute settings, to stop your page rank slipping through your fingers.
Over long periods of time, you make changes to your blog – sometimes resulting in a broken link structure. This plugin will help you overcome this, so next time your editing a post, or upgrading you can do so with content.
Hopefully if you have allowed you WordPress site to appear in the search engines, then by default your blog will be crawled and indexed. Sometimes you may want to avoid all your pages being indexed, you don’t want to get duplicate content and be punished now do you ? This will plugin will tell the search engine spider what to crawl and what to stay well away from.
Internal links play a vital role in your blog’s SEO score. Search engines will treat your sites internal links as an indication of how well structured your website is. This is often over looked, so this is where SEO Smart links help you! It totally automates internal linking between posts, you just specify certain keywords.
Images on you site, should have an ALT tag and be named in the correct way, not just for SEO but also for validation. This plugin will really help automate the naming of images across your WordPress blog.
On September 15, 2009, In SEO, WordPress, by Nick Stamoulis
Veteran copywriter Michael Fortin, in an interview about SEO copywriting, said that he has tested a variety of blog platforms and the one that always seems to do best for search engine optimization is WordPress. That’s an incredible statement.
Specifically, he’s compared WordPress with Typepad and some of the other popular blogging platforms available and WordPress [...]
Veteran copywriter Michael Fortin, in an interview about SEO copywriting, said that he has tested a variety of blog platforms and the one that always seems to do best for search engine optimization is WordPress. That’s an incredible statement.
Specifically, he’s compared WordPress with Typepad and some of the other popular blogging platforms available and WordPress always comes up on top. Why is that?
I think there are several reasons why WordPress does so well:
First, it has a great community of support. Being open source, there are thousands of people working to improve WordPress every day. Many of the people who are most involved in developing WordPress improvements are themselves successful Internet marketing and SEO professionals. Their work benefits themselves as well as the rest of us so it behooves them to improve WordPress’s SEO benefits whenever they can.
Another reasons WordPress is so good at optimization is because developers go through the trouble of creating plugins that are useful. These plugins and the source code of WordPress work together to build a solid platform for blogging.
Finally, WordPress has a reputation. Online, reputations matter. If you build a solid reputation for your product or service and word gets around, the search engines tend to honor that. Word of mouth reputations are important and it’s something that robots can’t measure. That means Google’s algorithms are built in part on human interactions and input, whether by design or fiat.
If you’d like to listen to Michael’s interview, you can download it here. It’s about an hour long and well worth listening to.