Some updates

It’s been a busy summer, so I realize posts haven’t been happening much lately.

I’m working on a lot of changes for this site, which will be happening shortly, as well as a few announcements related to some new projects I’m involved in, so stay tuned.

On another note, wordcamp Kelowna is shaping up nicely for September 11th, just a little more than a month away, and I’ll be saying more about that on here too as the time approaches.

Quick Function: Get a post’s slug in WordPress

Here’s another little function that tends to come in handy. Recently, on a project I did for a client, they had a sidebar where they wanted to display pages that were children of a main page. I whipped up this function to get the ID of a page’s slug and then perform a query:


function get_ID_by_slug($page_slug) {
   $page = get_page_by_path($page_slug);
   if ($page) {
      return $page->ID;
   } else {
      return null;
   }
}

So for example, you could then do a query like this in your sidebar:


$querystr = "SELECT wposts.* FROM $wpdb->posts wposts WHERE wposts.post_parent = '".get_ID_by_slug("white-papers")."' AND wposts.post_status = 'publish' AND wposts.post_type = 'page'";

And you would get all pages that are children of “white-papers”, it’s basic I know, but it works, and has a few other uses than just where I used it.

Quick Function: Check for parent category in wordpress

When I was working on foodjumper, there were times when I wanted to check the parent category, for example, if you’re in the Dinner category or viewing a post in that category, I want to display the proper layout for posts in the Recipes category.

One function that works, is to do a check like this:


function parent_category( $cats, $_post = null ){
     if( is_string($cats) )   $cats = get_cat_ID($cats);
     foreach ( (array) $cats as $cat ) {
          $descendants = get_term_children( (int) $cat, 'category');
          if ( $descendants && in_category( $descendants, $_id ) ) return true;
     }
     return false;
}

WordPress published a similar function on their site, but it used the actual category ID in the function. I found it easier to let you enter the slug instead.

Now, when you want to check if a post is in a category that is a child, you can do a check like this:


<?php
if(in_category('recipes') || parent_category('recipes') ):
     // display this post as a recipe
else:
     // display this post as a normal post
endif;
?>

This can be adapted to almost any type of similar treatment, I just used recipes above as an example since it’s where I just used this function.

Foodjumper.com, new foodie blog

Today, I’m pleased to announce the launch of FoodJumper.com.

FoodJumper.com is the end result of a month of planning, before even starting down the road of adding recipes and posts.

To put it simply, it’s a foodie blog, similar to foodizu.com, but different in that, this one is just me and also contains posts and videos, etc, whereas foodizu is a community of people adding recipes.

Why make another foodie site? Well, to put it simply, because I love food, so why not?

Quick Function: iPad Detection

Of course, the iPad is a pretty large screen and a fully capable browser, so most websites don’t need to have iPad specific versions of them. But if you need to, you can detect for it with .htaccess


RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]

This will redirect iPad users to a URL you specify.

Mentionedme.com: Website in 1 hour

MentionedMe.com was another website I recently built with the idea of providing a very quick solution.

I wanted to offer a site that would text you if you got a new mention on twitter, pretty simple process, and one that has uses for people monitoring their username mentions.

I decided to once again use the SMS API form twilio.com as a starting point since I’ve been using it quite a lot in recent projects, and then used YQL to perform twitter searches on usernames that are added.

The end result is that every 15 minutes, it does a check, and if there is a recent mention of your name, then you get sent text message saying “you have [insert number here] new mentions for @[insert your name here]“.

I used the YUI framework to quickly throw together the site design, and it’s been working well.

Despite all of the attention they have gotten recently, there isn’t a universal e-book format, and we must contend with the many different types of e-books that are available. Here’s a rundown of the ebook formats that are available today and how to use them all.

Quick Function: Inserting ads into your RSS feeds in WordPress

On my main wordpress site (this one your reading now), I like to display a single line below each RSS feed item that tells people quickly about some of my other sites.

The ad appears like this:

The code for it is pretty straight forward, and can also be used to display a copyright message linking to your site, or anything along those lines. Place the following code in your theme’s functions.php file:


function insertAds($content) {
  if(is_feed()) {
    srand((float) microtime() * 10000000);
    $banners = array();
    $banners[] = 'Banner number 1. <a href="http://www.somerandomsite/" target="_blank">Some more banner text</a>';
    $banners[] = 'Banner number 2. <a href="http://www.somerandomsite/" target="_blank">Some more banner text</a>';
    $banners[] = 'Banner number 3. <a href="http://www.somerandomsite/" target="_blank">Some more banner text</a>';
    $banners[] = 'Banner number 4. <a href="http://www.somerandomsite/" target="_blank">Some more banner text</a>';
    $rn = array_rand($banners);
    $content = $content.'
<hr />'.$banners[$rn];
  }
  return $content;
}
add_filter('the_excerpt_rss', 'insertAds');
add_filter('the_content', 'insertAds');

You could also replace this with banner images. Anyway, what this does is randomly select which text to display on your rss feed items. So for each article, you could have a different ad appearing.

If you wanted to use this to display only one message (like a copyright), you’d use this version:


function insertMsg($content) {
  if(is_feed()) {
    $banner = 'You are reading my blog. <a href="http://www.linktoblog/" target="_blank">Name of your blog</a>';
    $content = $content.'
<hr />'.$banner;
  }
  return $content;
}
add_filter('the_excerpt_rss', 'insertMsg');
add_filter('the_content', 'insertMsg');

That’s it, like I said, it’s a quick function, but it serves it’s purpose.


Back to Top