php

An alternative to wp_list_categories() – using get_categories() with a loop can prove to be quite useful in terms of customizing category displays.

Read More

Sometimes transitional content is used in one area of a website, like to display hours in a Header or Sidebar. Instead of having the client (or yourself!) update this content every day, get your code to update it for you when the weekdays change.

Read More

Use this to grab the Featured Image from the post parent if the child page is not using a Feature Image.

Read More

I have dug all over the internet for a query like this one!

This will generate the get_archives_link needed to link to your Custom Post Type year/month url.

Read More

Drop the below if statement within a loop and add a count for each colour change that you need with the template.

This is a great example to reference if you’re building a scrolling website, and loading all pages in a single progression with alternating templates applied.

Read More

Follow this WordPress Codex example and this support forum comment, add this into your header.php file and style the resulting body class accordingly

Read More

Get Category by Name

php

June 26, 2015

Retrieve the ID of the first item in a loop:

$category = get_the_category(); 
echo $category[0]->cat_name;
Read More

For use with older browser version testing.

Read More

Create a menu that drills down to subpages as they exist.

Read More

Create two functions within functions.php. One will control the “if(has)” parameter that will be called within the page template, and one will contain the data that we want to display:

Read More

Follow these instructions to exclude custom post type category.

Read More
$top_page_url = get_permalink( end( get_ancestors( get_the_ID(), 'page' ) ) );

Use the above text in place of the_permalink(); in order to retrieve the link information for the topmost page ancestor.

Read More

Post Content by ID

php

May 13, 2015

echo apply_filters('the_content', get_post_field('post_content', $post_id));

Sourced here.

Update – July 28, 2015

This method can also be used to retrieve data from custom fields when working with plugins like Advanced Custom Fields:

echo apply_filters('widget_content', get_post_field('widget_content', $post->ID));
Read More

If page IDs or other classes are not appearing in the source code for a site that you’re working on, check the header.php file to see if body_class(); is being applied to the <body> tag.

Read More

Working with large sites that have cross-over content, sometimes it’s necessary to know how to bring multiple taxonomies into a single query.

Read More

PHP Redirect

WordPress

April 22, 2015

When creating parallax websites, or websites where all of the content is visible on one area, use the following to keep users from getting sidetracked from other areas of the website

Read More
<ul>
  <?php $n = 0; foreach($page->children() as $child): $n++; ?>
  <li class="<?php echo ($n%2) ? 'odd' : 'even' ?>">
    ...
  </li>
  <?php endforeach ?>
</ul>

You can change “odd” and “even” to whatever names you need.  Sourced here.

Read More

Using large sliding banners with linked content can be both a blessing and a curse.  This adds a beautiful level of style and information to the site, but also takes up a lot of space, and provides a lot of repetitive information that can be difficult for new visitors to navigate.

Read More

Auto-Updating Copyright Year

php

December 02, 2014

Using the_date(); this is very easy to achieve, all you need is  &copy; to get yourself setup. To take it a step further, you can include a date span, so your clients are aware of just how long you’ve been burning the midnight oil.

<p>&copy; 2013 <?php date('Y') == "2012" ? $year = "" : $year = "- ".date('Y'); echo $year; ?></p>

Sourced here.

Read More

Place this within the single.php template to grab the Featured Image and format it automatically inline with the content.

the_post_thumbnail('large', array('class' => 'alignright'));

This can also be used in the loop with alongside posts with featured images.

Read More

List Child Pages

php

September 30, 2014

Menus can be tricky. Rather than being locked into the just using menu sort order, or alphabetical order, combine the two using wp_list_pages(); You can style the drop downs to respond on hover using CSS.

Read More

I’ve run into problems several times where exclude and include do not work, or work selectively, and as a result, either all of the posts are included, or none of them are. I’ve found an answer that works both inside and outside of the loop.

Read More
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.