Archive for August, 2009

Adding the “Blog” page with PHP

Posted by Greg August - 10 - 2009 - Monday ADD COMMENTS

As mentioned in a previous post, I wanted to add a link to the “traditional blog” layout… just a bunch of posts in reverse chronological order. When my dad came over for a visit today, he reinforced this need– “I like your new layout, but how do I just go to the blog?”

Seemed simple. The Androida theme, upon which the new layout is built, includes 2 different layout options– “business” or “blog”. Surely I just have to link to an appropriate .php file to get what I want, right? Nope… doesn’t work that way. So I set off to find the solution. Now, I don’t know why I couldn’t find any solutions through Google, but I couldn’t. I don’t know why I couldn’t get a plug-in to do this for Wordpress, but I just couldn’t find one.

So, I cooked up my own “hack” for the theme. It’s not pretty… there’s definitely a way to make it more integrated with the theme options. My way is hard-coded, which means that the theme isn’t portable without manual tweaking. So, I’ll clean it up some day if I ever want to contact Web2Feel to ask them if I can release an Androida Redux theme. But in the meantime, I had to have that link, so the quick and easy solution was the way to go.

How it’s done

What Needed Changing

Wordpress loads an index.php page from its root directory, which in turn loads another index.php page from inside your theme folder. When you look at Androida’s particular index.php it looks like this (formatting my own):

1
2
3
4
5
6
7
8
9
10
<?php get_header(); ?>
<?php  
  if ($layout = get_option('andro_layout'))
  {
    include (TEMPLATEPATH . '/layouts/'. $layout .'.php');
  }
  else
  include (TEMPLATEPATH . '/layouts/business.php');  
?>
<?php get_footer(); ?>

In English: Get the header (loads header.php). Then check to see if there’s ANY option set in Androida (just a sanity check). If there is, use the template found in the template directory, plus the subdirectory “layouts”, with the filename $layout.php. If you have set an option in Androida, the $layout variable translates a “business” or “blog”, so the filename becomes either “business.php” or “blog.php”. Otherwise, if there’s no option set at all by Androida, use “business.php” (in other words, business.php becomes the default). Then get the footer (footer.php).

This means that you can only use one layout or the other with default Androida.

How I Changed It

However, PHP has a $_GET function which I can take advantage of. All this function does is “look at your address bar” and extract any variables that appear after a “?”. You’ve all seen these… in your address bar you’ll see something like “http://www.mywebpage.com?username=Greg&favhockeyteam=Senators”.

So, all I needed to do was invent an arbitrary new variable (I called it “pagetype” but you could call it “fuzzykittenpaws” if you want) and use it to tell Androida’s index.php something new.

In English: I wanted it so that whenever you put “http://blog.monkey-house.ca?pagetype=blog” in your address bar, you would see a blog layout.

For this to work, index.php needed to understand what to do with “pagetype”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$pagetype = $_GET['pagetype'];
?>

<?php get_header(); ?>

<?php
if ($pagetype == 'blog') {
    include (TEMPLATEPATH . '/layouts/blog.php'); }
else {
    if
      ($layout = get_option('andro_layout'))
    {
    include (TEMPLATEPATH . '/layouts/'. $layout .'.php');
    }
    else
    include (TEMPLATEPATH . '/layouts/business.php');
}
?>
<?php get_footer(); ?>

Most of the code is the same… that whole middle part is identical, you’ll notice. I could have “refactored” the code, and in fact I could have used the $layout variable instead of my new $pagetype… but that would require more refactoring than it was worth. So,

In English: Declare a new variable called $pagetype by using $_GET to grab it from the address bar (if there is no ?pagetype=blog in the address bar, $pagetype will become “null”, which is fine). Get the header (just like before). But now, first thing to do is check to see if $pagetype is “blog”. If it is, load the blog.php template file. This implies that if it is NOT “blog”, execute the rest of the original Androida code. Then get the footer.

Adding a Link to Navigation

The final thing I needed was a link. This is where the hard-coding breaks the portability of the theme. I opened “header.php” and located the following:

1
2
3
4
<ul class="lavaLampBottomStyle" id="A">
    <li><a href="<?php echo get_option('home'); ?>/">Home</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>
</ul>

This is located inside my menu div. All it does is set a “Home” link, which gets a valid URL from Wordpress, and then uses the standard “Pages” list to generate any links based on “Pages” I have (as of this writing, I have none… but that might change).

All I had to do is add an extra item to the list… a hard-coded link containing the URL with the pagetype variable–http://blog.monkey-house.ca?pagetype=blog.

1
2
3
4
5
<ul class="lavaLampBottomStyle" id="A">
    <li><a href="<?php echo get_option('home'); ?>/">Home</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>
    <li><a href="http://blog.monkey-house.ca?pagetype=blog">Blog</a></li>
</ul>

It will actually be relatively easy to change this hard-coding to make it portable… it just needs to become another Androida option. But that’s for another day. ;-)

New design, now featuring more monkeys!

Posted by Greg August - 5 - 2009 - Wednesday ADD COMMENTS

As you can see, the site is undergoing a redesign.

I think I’ve learned enough about web development and WordPress to design one from scratch, but I know myself, and I know the path to ruination that would bring. So, I’m taking a theme that’s slightly less than perfect for my needs and making gradual changes. The assumption is that the things I would like to change are at least “tolerable” for now, and that I can therefore take my sweet time changing them.

Excruciatingly boring to most readers, but here’s what the strategy is:

  1. Start with Web2Feel’s spiffy Androida Theme
  2. Change the core look and feel and redesign a custom header using our Monkey House branding
  3. Make sure the most absolutely important base functionality is restored and/or created:
    1. Make a link to a “Blog” page that lists the whole sequential blog for people who like that kind of thing
    2. Get rid of the banner spaces… I don’t need no stinkin’ banners… nobody pays me for advertising space! Maybe a Flickr widget would be cool…
  4. Fix a visual artefact in the slider
  5. Write some PHP to complement the slider… when a gallery image isn’t specified, some sort of default placeholder image is put there
  6. Fully Widgetize any area that can sensibly be widgetized
  7. Modularize the whole thing so that child themes can be made with simpler CSS and fewer image changes

Not to criticize the folks at Web2Feel. This is one of the best FREE themes you can get. But it has some flaws, and I think it will be fun learning how to fix them.

So far, I’ve obviously done the first few steps. It was a lot of fun taking the basic monkey and logo created by Jan at Dawghouse and creating new Alex and Cole monkeys from it.

Next step… get a “Blog” page ready.

1st Anniversary!

Posted by Greg August - 5 - 2009 - Wednesday 2 COMMENTS

wedding_rings_smaller

A bit of a delayed post… pretty rude to post something when it’s your anniversary, I would imagine!

So, we recently celebrated our first wedding anniversary. Leading up to it, we had discussed whether to go with the traditional anniversary gifts (paper, then… er… well, I didn’t research what year 2 is supposed to be, if anything…) and opted to go for it. But then life happened, and we didn’t get around to the whole gift-buying thing. It’s not “too late” in our world. At least one half of our clan is notorious for buying delayed gifts, and since it’s Mama Monkey’s half of the clan, I’m not in the doghouse.

As it turns out, trying to celebrate an anniversary when you have a 7 wk old baby is a bit of a challenge! Here’s what the plan was:

1. Afternoon on the market; baby in a sling or wrap, us buying nice fruit, cheeses, and generally enjoying a stroll.
2. Dinner at home, provided by my wonderful parents… they knew we’d eat at home (obviously) and had brought us some yummy treats from M&M.
3. Drive-in movies (this time armed with ways to combat mosquitoes!). Harry Potter is playing.

Here’s the reality:

RAIN.

So, we opted for a nice quiet day at home. To spice it up a bit, and because I did not feel like BBQ’ing in the rain, we got some take-out from our favourite Sushi restaurant, Sushi 88. I’m usually a pure sashimi guy, but I had a hunger on, so we also got some yummy specialty rolls. That’s a tradition I can get into… a good roll is teh yummay! Once the sushi settled down, we topped it off with a wicked-good bumbleberry pie that was part of the M&M treats.

Well, the intention of this post isn’t to bore you with the minutia of our lives, but rather, as an excuse to say the following:

Alie, I love you so much. I can’t imagine a life without you, and I’m so glad that this was only the first year out of many to come. You are my soul. Happy Anniversary, baby!

About us

Monkey House is populated by three lovely and wonderful simians–Greg, his wife Alex, and their son Cole. He is a jack of all trades, she is a scientist/athlete, and their son is a poopsmith.