« Archives in March, 2012
31
March

Weekly Catchup – S2E5

Welcome back everyone,

Gees, it’s been a hectic week! I’ve had to get up at 6 for three out of the five days this week, because of meetings with either my EM group or the client for my group project. It’s been really fun, though. Thankfully, these next two weeks are university “holidays” so I will be able to get a bit of rest in the mornings. That said, I still have work to do for my courses, so it won’t really be a holiday (hence the use of quotes above).

Before I get into what happened this week, I would like to ask you all a question. I will try to get posts up in other categories every so often during the break, but I’d like to know if you’d like me to continue this series as well. I don’t know if I’ll have too much to talk about, though. Leave your answer in the comments below.

Monday: Monday was like most weeks. Got in around 10am, as usual, and met up with my friend in the BESE lab. For the most part we just chatted about the project and other assignments. I also decided to print off a paper for this week’s SPI review. Probably should have read it too, but oh well. A bit later on I had a meeting with my EM group. We were able to get some of the slides and a small plan prepared for the assignment, which I was happy with. Looking back, we probably should have done more, but it doesn’t matter now. After that meeting, I just went back to the BESE lab and continued procrastinating until the lecture for the day (SPI). It was a pretty average lecture again. Nothing too interesting came out of it. I like how quickly the lecturer finishes the content, though. Always like leaving before 6 on a Monday. Before leaving, my team mates and I discussed meeting up in the morning for the client meeting. We decided to meet up at 9 so we could organise ourselves beforehand.

Tuesday: First early day for the week. My team met up around 9, like we planned, and started getting things ready to show the client before heading down to the meeting room. Turns out everything we’d done during the week wasn’t what he wanted (or he didn’t understand how it fit with his thoughts). We were able to find out a lot more information, though. We were all happy to get that new information. After the meeting we had a small chat with the project supervisor (since he asked us whether we thought the project was doable). We (basically) said it was, as long as we can find out the ideas the client has for it. Afterwards we went back to the BESE lab to start creating some more mockups (on paper this time). We then set each other some tasks before having to leave for other things (mine being another EM group meeting, to continue getting the assignment done). We had planned to make a video as part of the presentation, but (during this meeting) decided to just take photos instead. That was actually pretty fun. We got some good photos out of it too. After getting all the photos we needed, I went back to the BESE lab to meet up with my friend again. We played some Minecraft for a few minutes, before his laptop fried itself once again, then just chatted a little more about the project before going home.

Wednesday: The last day this week I got a little time to sleep in. My project group had planned to have another meeting at 11, to look at what we’d done overnight and plan some more for us to do. Unfortunately, our team leader went shopping for a suit (since he had a job interview the next day). He didn’t get in until about 12:30! By that time, we could only tell him about what we’d discussed before leaving for the SPI practical session. It was another pretty easy program to make again this week, but it took us all a fair bit longer because we also had to do a design and two reviews (one for design and one for code). I barely finished it by 4! Kind of glad I got it done then, though. Didn’t have a reason to leave early.

Thursday: Second day up really early. This time for yet another EM group meeting. We were able to work through more of the slides for the presentation, but weren’t able to create the quiz we were going to include as part of it. Turns out the software we wanted to use, Articulate Studio, doesn’t seem to like my computer. I don’t think it’s coded too well, since it was really buggy for both members in the group that tried using it. So we just did what we could of the slides before departing. The rest of the day I spent just working on my review for SPI. The paper wasn’t as interesting as I hoped this time around. Next time, I think I’ll go with one that is more to do with what the course is about. My friend that had the interview came in a bit later during the day, after his interview (and after I’d finished my review). We first chatted about his new laptop (a brand new Dell XPS – looks pretty sweet), before starting up Minecraft. Gees, that was fun. Didn’t have to worry about his computer overheating, so we got to play a bit longer. Afterwards, I had my CV lecture. It’s getting really mathematical now. I think I understand it, but it’s not really what I first expected from the course. Oh well, we’ll see how I go.

Friday: Last day of the term! And last day I had to be up at 6! My EM group met up for the last time to completely finish the presentation. We were able to get a heap done, which was really satisfying. Took us 3 hours to get it all done, though. And even then, there was still a couple things left to do on it (which one member did after their lecture for the day). I’m really happy I didn’t have to worry about it any more. After the meeting, I went to the BESE lab to do a little procrastinating. During the time I was there, a couple of my friends turned up to say hi. It was really good to catch up with them. For the most part, we just chatted or worked on assignments.

That’s pretty much the whole week. Thanks for reading.
Robert

25
March

Weekly Catchup – S2E4

Hello, everyone. Sorry this is a day late, but I was busy all yesterday working on an assignment. It’s been another very long and busy, but fun, week. I’ll get straight into it.

Monday: No EM lecture! It was cancelled due to the guest lecturer we were supposed to have not being able to attend because of a “family emergency” (as we were told). That brightened my day when I read the email about it (not the family emergency part, but not having that lecture). I still went into university early, though. Most of the day I spent just chatting and doing work with my friend in the BESE lab. I also tested out a tool we’ll be using during the semester as part of the group project – FishEye by Atlassian. It’s a pretty interesting program. Looks and works a little like Facebook (but not completely). At 4, we went downstairs for our (other) lecture for the day – SPI. It was a pretty average lecture, mostly just about the different regression methods used as part of the SPI Tools system we’re using during the practicals. Not too interesting, but useful. I guess. After the lecture (which finished early again), my project group talked about what we’d need to do before the meeting with the client on Tuesday.

Tuesday: I had two meetings on Tuesday! One was for my EM group, and the other was with the client for the group project. I started out the day preparing with the rest of my group in the BESE lab (mostly just creating an agenda for the meeting). That took a few hours, because the rest of my group also had meetings with their respective EM groups. I had my meeting at 1. Sadly, only three of us turned up. We were about to brainstorm some pretty interesting ideas for the assignment within the hour, which I was happy with. Don’t know if they’ll be used in the final thing, but we’ll see. After the meeting, I went back to the BESE lab and finished preparing with the rest of my group. We just needed to print off our agenda and group CV, then talk through some final things. The meeting before ours ran over, which was a little annoying. It gave us time to have a small chat with our client, though. He seemed like a really nice guy. During the meeting, we all got a bit of a shock about what we need to do for the project. We thought we’d need to create the whole dependency system from scratch, but it turns out they already have the system in place and we just need to create a GUI system over the top of it. They want that so they’re able to visualise the dependencies, instead of needing to read some (many, many pages worth of) text in the command line. For us, it was a major brain overload! But simplified a fair bit of the work. After the meeting, my group talked about what we need to do now. We decided to have a meeting in the morning, and to work on creating mockups and user stories overnight.

Wednesday: Got in a bit later than I wanted to on Wednesday, but still early enough to have some time to pick a paper to review for SPI. Somehow, I also had time to read it through once. At 11, the third member of my group turned up (my friend was already there) and we started talking about the look and how we’d code the program for our project. Turns out we’ll most likely be going with something looking pretty close to the look of the mockup I’d done Tuesday evening. We all seemed to like the look of it. We also looked into GUI systems for python (the language we’re going to be coding in). That took us a fair bit of time to get set up. At 1, we went over to the lab for the SPI practical. It was a really, really simple system this week! Only took about an hour to complete. Mainly because we were able to reuse the first program (with some changes), but still. Oh well, just means a very early finish.

Thursday: Thursday was a VERY long day! For most of the day I just worked on my review for SPI. I’ve pretty much gotten into a routine for completing it – read through it once, read through it again and note down dot-points, write the overview and significant contributions from my dot-points, then think about and interpret what I’d just written for the “relationship to my understanding of the PSP” section. I don’t know how I’ll go with it, but I think what I did should get me high-ish marks. During the day, one of my friends turned up. I had to let him into the lab, because he doesn’t actually have swipe card access. We chatted for a bit before getting to work on our own assignments. After I’d finished the review, it was just about time for my one lecture for the day – CV. It was a fairly interesting lecture. But, then again, it was a lecture. I think I’m understanding most of the content, though.

Friday: Very early mornings are annoying. Friday’s EM lecture was another guest lecture – with 5 people from GHD! I didn’t really find it that interesting, to be honest. Just another lecture. Afterwards, I had another meeting with my EM group. Four of us turned up to it this time, which was better than on Tuesday. We were even able to organise exactly how our presentation will work! I was happy with our progress. Not that I’m really that interested in the course, but it’d be good to get it done well. After that, I went over to the BESE lab to catch up with my friends. We mostly just chatted about random things, plus a little about the careers expo that was on. We organised to meet up around 2:30 to take a look at all the companies that had come along. The companies that we went to were pretty interesting. We got stuff from most of them (that do software engineering, anyway) about their graduate programs, then just left for the day.

That’s pretty much my whole week. This post probably doesn’t make it seem like it, but it was really busy compared to most other weeks. I think this coming week will probably be just as busy, if not more!

Thanks for reading, everyone.
Robert

18
March

How to: WordPress Themes (part 3)

Hello once again.

Welcome to the final part of this tutorial on WordPress themes. As I said in the last post, this one will be on the functions.php file. This file allows your theme to act as a plugin, in that you can set up hooks and filters into WordPress’s functionality. It also allows you to tell WordPress what functionality your theme gives access to. For example, you can turn on custom sidebar support, custom navigation bars, even post thumbnails.

For my own themes, I usually do something like the following in the functions.php file:

<?php
define('THEME_NAME', 'Dialog');
 
// turn on sidebar support
if(function_exists('register_sidebar')){
   register_sidebar();
}
 
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
 
// turn on thumbnail support
add_theme_support('post-thumbnails');
set_post_thumbnail_size(200, 150, true);
 
// add feed links to header
add_theme_support('automatic-feed-links');
 
// turn on navigation support
function dialog_reg_nav() {
   if(function_exists('register_nav_menu')) {
      register_nav_menu('main-nav', 'Main Navigation Menu');
   }
}
add_action('init', 'dialog_reg_nav');
 
function dialog_scripts(){
   if(!is_admin()){
      wp_enqueue_script('dialog-core', get_template_directory_uri().'/js/dialog_core.js', array('jquery'), '1.0', true);
      // Required for nested reply function that moves reply inline with JS
      if(is_singular()){
         wp_enqueue_script('comment-reply');
      }
   }
}
add_action('wp_print_scripts', 'dialog_scripts');
?>

The first line (define('THEME_NAME', 'Dialog');) isn’t required, but is useful if your theme includes multi-language support.

The next part first checks if the WordPress version running the theme contains custom sidebar support (older versions didn’t) and tells the system to enable that feature. This enables the widgets section of the WordPress admin pages, and allows dynamic_sidebar to do something useful.

add_editor_style, as the comment above it suggests, turns on visual editor styles support. Basically, you can create a CSS file called “editor-style.css” that contains the styles from your main theme styles for the content part of the theme. This allows authors to see what their content will look like after it’s been posted in real-time.

Next, some extra theme support is enabled. In the above example, post thumbnails and feed links in the header part of the page are turned on. The post thumbnails support tells WordPress that it can print the thumbnail for the featured image if the post contains one. The feed links in the header are helpful for spiders and crawlers, as well as browsers that can read RSS feeds. These links are output as part of the wp_head hook talked about in part one of this tutorial.

To enable navigation support, you need to tell WordPress later in the start up that you support navigation bars. To do this, you need to create a function that enables the feature then hook it to the init hook. For WordPress to know that your theme supports custom navigation bars, you need to give it a “nice-name” for the navigation as well as a display name (that the user will see). Because of this, you can support multiple navigation bars in different places.

The last part of the above functions.php file is for any JavaScript files that you need to use as part of your theme. All of my themes use similar scripts which are included using wp_enqueue_script. This function tells the system to include the script file in the header (or footer) by the “nice-name” given as parameter 1. If it doesn’t know about the script you’re talking about by default, you can define it as part of the same call. There is also a function for defining your own scripts for inclusion, which I’m not going to talk about in this post. The theme using this functions.php file also includes WordPress’ own comment reply scripts, which allows visitors to click reply on a comment and have the comment box appear in the place they are wanting to comment.

You can also use functions.php to create your own functions for use within the theme. For example, you could have a functions that outputs information about what the user is currently looking at (archive, calendar date, etc). Or you could create an admin page for the theme, if you want to give the user the ability to change theme settings. The admin page creation for themes is exactly the same as creating admin pages for plugins – so if you know how to create admin pages for plugins, you already know how to do it for themes.

This is pretty much everything you need to create a working WordPress theme. Hopefully you were able to follow along and create your own theme. If you need any more information about creating themes, I’d suggest checking out the WordPress Codex. It’s got a lot of information about everything to do with themes, plugins, and even using WordPress itself.

Happy Coding, everyone!
Robert

17
March

Weekly Catchup – S2E3

Hello, everyone!

It’s been another long and busy week! I’m starting to catch up on my backlog of assignments, but I’ve still got a fair bit to complete. To those waiting for the final post in my WordPress theme tutorial, I will get around to that in a day or two – I promise. Anyway, lets get into this week.

Monday: Public Holiday! Thank goodness it was. I spent most of the day working on my presentation for the honours and masters retreat on Tuesday. My talk was called “On Web Development”, and was all about my whole website (including this blog). I also spent some time playing around with my new phone I got over the weekend. It’s pretty cool. Aside from these two things, the day was pretty quiet.

Tuesday: The honours and masters retreat day. To get to it on time, I had to get up at 6. I hate 6am mornings. But it was a really good day. For the most part it was made up of everyone’s talks, but we also got free food and drinks. Some of the talks were pretty funny too. At the end of the day, we also got a free dinner at a mildly fancy restaurant in the city. The food was really nice! We were also able to have some pretty funny conversations. All in all, an awesome day of socialising with the other students and staff involved.

Wednesday: Back into work mode. First thing I did when I got into university, after meeting up with my friend, was start my second review for SPI (since that was due on Friday). I spent about an hour figuring out what paper to review and reading the one I chose. It was a really long paper. But pretty decent for information. The rest of the time before the SPI practical session I spent just chatting with my friend and watching a YouTube video. A bit before 1 we went down to the lab for the practical. I was able to get it (pretty much) completed within 2 hours! Unfortunately, after getting home, I found out my program divides by 0 (not a good thing). So I had to quickly fix that and resubmit.

Thursday: I met up with my friend in the BESE lab once again and continued working on my review while chatting with him and his partner (she was there too). For most of the day we all just worked on assignments and chatted when we found something to talk about. I was actually able to get a fair bit of my work done, which I was happy with. Didn’t get everything done, though. But oh well. At 4 I had my CV lecture, which was decent. It looks like most of the course is going to be mathematics based, which I’m not too excited about. It’s understandable concepts though, so I should be alright. Hopefully. Most of the first hour of the lecture was spent going over last week’s content, basically as a catchup. I don’t really know why, though. The second hour was all new content, which seems pretty interesting. It was about distorting and sharpening images using filters, and the mathematical formulae for them. I also found out during the lecture that my laptop can last 3 hours just on battery! I have to disconnect the WIFI, turn the screen brightness right down, and close every running program for it to get that much time, but it can do it.

Friday: I had to go into university pretty early again. This time not for a lecture, but for a meeting with my group for EM. It was a pretty awkward meeting, to be honest. But we got through it and figured out some ideas for what we need to do for the first group assignment. The meeting went for nearly 2 hours too, which surprised me. After the lecture, I went to the BESE lab to find my friend with his partner again. I chatted with them a bit, and asked my friend to have a read of my SPI review (since I’d finished it the night before). He said it was good, which made me happy. So I submitted it, then worked on the assignment for EM – an improvement plan on what we can improve upon during the semester and reflection on one of the topics in the plan. I hate it. Probably the worst assignment ever! I was able to complete the improvement plan in about 3 hours (yeah, OK, I procrastinated – I’m sure you would too if you had this assignment). After that, my friend and I decided to play some Minecraft (since we hadn’t since last week). That was pretty fun, until a creeper blew up right by me and destroyed a part of our (small) house. Then my friend’s computer decided to die on him (it is getting a little old). So at that point, we just stopped and chatted a bit before going home.

Well, there’s my pretty hectic week. I’m surprised I was able to get so much work done, but really glad I did.

Thank you for reading this week’s catchup. See you all next week.
Robert

10
March

Weekly Catchup – S2E2

Wow, two weeks down already! This past week has been a lot busier than I expected, so I wasn’t able to post the final of my tutorials on WordPress theme development. For those interested in it, I will be doing that this weekend, so look out for it. Anyway, lets get into what’s happened this week.

Monday: I found out over the weekend that I had a review to complete for SPI due on Friday. When I got into university I met up with one of the guys in the SE lab and chatted a little before looking into the assignment. Turns out we had a whole list of papers to review, and could choose from any of them. I decided to go with one titled “Software Development Process Animation”. For a research paper, it was really interesting to me (usually I’m not too enthusiastic about research). After reading it through once, my friend and I kept chatting for a bit before deciding to play some Minecraft. That was pretty fun. We played for about half an hour before we went back to working on our reviews. At 2 was left for our lecture – EM. This lecture started out as a discussion about the first assignment, before going onto an introduction of the second assignment. I found it pretty annoying that the lecturer had to explain every detail of them to us, but I guess it’s better that they did. Makes it easier to complete them. After that lecture, the guys and I went to the SPI lecture in Innova (or Ingkarni Wardli, as it is now known) basement. It was a pretty quick lecture, but just more of the same from last week – the SPI Tools system and the statistics that go with it. The lecturer finished early again, which I’m happy with.

Tuesday: I got into university to find I’d have to spend some time alone. I was pretty happy with that, though – gave me time to work on the SPI assignment. For the most part, I just read through the paper again and took down some important points to talk about in my review. I got a fair few down, actually. Around 12 my friend came in to say hi before heading off to a workshop he’s a demonstrator for. I just continued getting points down for my review. When he came back at 2 we headed down to the basement to try and catch up with our lecturer for SEGP, even though the lecture slot wasn’t being used as a lecture (just a free couple of hours). We met up with two of the members of my SEGP group from last year, who didn’t know the lecture was off. So we chatted with them about courses so far, and the projects for this year. After 15-20 minutes we left to go back upstairs, since it didn’t seem like the lecturer was coming, and just chatted a bit more before heading home.

Wednesday: Once again, I met up with one of the guys in the SE lab in the morning. We did a bit of work on our SPI reviews before starting up the Minecraft server and playing for about 20 minutes. At that time, he had to leave for a meeting with a lecturer. I just jumped back into completing my review. I was able to get almost two sections complete before heading off to the SPI practical session at 1. I was really happy with my progress, though. This week’s practical we were required to create a program that counted the number of lines and items within files coded in the same coding standard we have to adhere to within the course. It was a really, really simple program. Only took me about two and a half hours to finish (along with the rest of the process). Once I’d finished, I just went home.

Thursday: When I got into university on Thursday I found my friend working on a small Javascript game that the lecturer asked him to create as an assignment for the first years. The concept of it sounds pretty cool. And once my friend had finished with the code for it, it looked pretty awesome too. I wasn’t able to take too much of a look at it though, since he’d gotten me to watch the “Kony 2012” video on YouTube. All I’m going to say is that, if you haven’t already, you should look it up and watch it. After I’d finished the video, we talked about it a bit. We then also got in contact with our client for this semester’s group project (since we’d just found out from looking on the forums) before he had to leave for another workshop. I stayed behind and looked (literally) at my review for SPI. A bit before 2 we had to evacuate, being told over the intercom during the alarms that it wasn’t a drill. Once everyone was outside, we were told to just leave for two hours with no other explanation. Annoyed me a bit, since I didn’t have anywhere else to go (besides home). So I thought I might as well just go home (even though I had a lecture on at 4). On the way I sent a message to a mate of mine who volunteers in the CFS (Country Fire Service), asking if he knew anything about the evacuation. He called me back saying there was supposedly a “suspicious package” within an engineering building. The university never gave any information out about it, and it was never on the news, so I’m guessing it may have turned out to be a false alarm.

Friday: Ahhh, TGIF! Kind of, anyway. Had the very early start again, which sucked. But the lecture for the day was actually pretty interesting. A lot better than the other 3 lectures we’d had. We also finished really early, which made me happy. On the down side, we were given yet another assignment. At least it’s a group one. After the lecture, one of the guys and I went to the SE lab and jumped straight into some Minecraft for nearly an hour. We both did a fair bit of exploring within caves before he left. After he had, I got into finishing up my review. I was very happy when I got it all done with 61 words to spare (it had to be between 400 and 600 words)! I then submitted it, and moved onto watching YouTube videos. When my friends started turning up again, I stopped watching them and just chatted about assignments. After a while, two of us got back into Minecraft once again! We explored caves a bit more before creating a portal and travelled to the Nether. We didn’t stay for too long, though. At that point, we disconnected and left university.

I actually enjoyed this week, even though it was so busy. Next week I think will be a fair bit more busy, so again I may not post too much. I will try to get something up soon.

I hope you enjoyed this episode. Thanks for reading.
Robert

02
March

Weekly catchup – S2E1

Wow, one week down already. Just me, or has this week just flown by? This week has been pretty awesome! Lectures have been fairly decent and interesting, and not much work has been given out as yet. In fact, most of my time has been spent just being lazy (aside from getting up at 7 every day). Lets get into the details, shall we?

Monday: The morning was the usual routine for a university day – up, breakfast, shower, etc. before heading off into the city. By the time I got to university it was about 10 – my first ever “lecture” (or tutorial) wasn’t until 2pm. Fortunately, a few of the guys I’m friends with turned up a bit after me, so I just sat chatting with them for pretty much the whole time until the lecture. It was really good to catch up with them. When I headed off at 2pm (for the “lecture”/tutorial), I bumped into another guy I’d become friends with! We chatted for a bit, but had to end it fairly quickly to get to our own classes. My first course for the year was “Engineering Management IV” (EM). This first one was just a basic introduction to the course, what is expected of us, how the course will be run, etc. Basically just the usual spiel lecturers are expected to give within the first lecture. It seems like an alright course, but I’m not too excited about it. The introduction ran for half the two hour slot, so my fellow engineers (one being in the group of guys I’d hung out with earlier in the day) and I just went back to the software engineering lab and chat about our courses for this year. At 4, we went down to the basement for our first actual lecture – Software Process Improvement (SPI). This course seems really interesting, albeit a little weird. The lecturer went through the introduction spiel, as expected, then jumped right into the course content and an explanation of how the course will be run. The topics we’ll be going through – basically just to improve ourselves as programmers and engineers – seem really cool. We also got a quick introduction into the process we are required to use for the practicals – that’s where the weirdness comes in. The lecturer (nicely) finished before 6, so we were able to leave fairly early. I was happy with that.

Tuesday: When I arrived at university on Tuesday, I found one of my friends with his partner working on an assignment and setting up Virtualbox. So I just chatted with them, and helped out if either of them needed a bit of help. Between when I got there and 2pm (when my next lecture for the semester was on), both of them had other appointments to go to (eg. lecture for one, and a meeting for the other). In the time they weren’t there, I worked on parts of a project manager we’d started designing and planned to use during the year. Unfortunately, that plan seems to have fallen through (we’ve found other tools that do the same things we want). At 2, I went downstairs for my lecture – this one being the Software Engineering Group Project 2 (SEGP) course. I was surprised to find out we were sharing the lecture time with the masters students (I was thinking it’d only be the BESE and Honours students). This lecture only lasted an hour, which was pretty cool. Got to leave early again. The lecture was mainly to introduce us to how the course will be run, and what projects will be available for us to choose from and complete during the year. My group (the three honours students) thought it’d be interesting to go with a project offered by Rising Sun Pictures. At home, I decided it was about time I started my WordPress theme tutorial (which you can read here).

Wednesday: Tuesday after our lecture, my group had organised to meet up at 11 to take a look at some tools that we could potentially use during the year to help with the project. Unfortunately, one of the group was sick (had been getting a bit bad over the 2-3 days leading up to Wednesday), so it was just two of us that looked at the tools (particularly JIRA and Confluence from Atlassian). They both seems really interesting and useful, so we’ll most likely be using them. A bit before 1 the sick member of the team turned up, just to attend the first practical session for SPI. This session was pretty interesting. It was set to give us an introduction into the process and system we have to use during the semester. I can’t say for certain, but I think I may have been the first person to complete the practical, since the lecturer partially used me as a test subject for the submission process. At the end of the session, I stayed back for a bit to help out my sick team mate finish up with the process and submit his final program.

Thursday: For some reason I decided to go in for 10 once again, even though I didn’t have anything on until 4pm. Most of the day I just sat in the BESE lab, getting more and more bored. After a while, I decided I might as well continue my WordPress theme tutorial (you can find part 2 here). That took up the majority of my time, and kept my mind fairly active until a bit before 4pm. At 4, I went downstairs once again for the first Computer Vision (CV) lecture. It seems like it’s going to be a pretty interesting course – we’ll be using Matlab (a mathematics program that deals mostly with vectors) to analyse and try to get the computer to recognise images. I’m pretty excited for that. I’m not too happy with the finish time, though – 6pm. That makes two days a week I’ll be in later than I have been any other year.

Friday: Today I had to get up earlier – 6am! – because I had a lecture at 9. This was the actual lecture for EM. I think I may have left home a bit later than I should have. I had no idea where the lecture was being held (so I had to go to a computer and check), but then I still didn’t know where the lecture theatre was. I figured it out, though (with the help of my, now much better, team mate). We got into the lecture a bit after the lecturer had started (strangely – when I looked at my phone’s time, we were right on time). That lecture was really quite interesting. For the most part, it was about the Myers Briggs Type Indicator and what the letters that make up the indicator stand for and mean. We were also told that we need to complete an online test/survey, which will allow the lecturers to create our groups for the course. Turns out I’m an ISTJ. What are you? (post your result in the comments below). After the lecture, my team mate and I just went up to the SE lab to complete the test/survey and chat a bit. He left shortly after, then came back a couple of hours later with his partner and another of our friends. Between then and about 4:30pm, we chatted about the EM lecture, programming (since my team mate’s partner had another assignment to work on), and played some Minecraft on a server I was running on my laptop. That was actually really fun.

I think that’s pretty much all the most important points from this week. Thanks for reading!
Robert

01
March

How to: WordPress Themes (part 2)

Welcome to part two of my how to creating a WordPress theme.

In the last part I showed you what files you’re required to have for WordPress to recognise your theme, the optional files WordPress uses for different types of posts and pages, how to split up your code between multiple files, and started going through the many, many template tags that you will want to use within your own theme. I left off at adding in the tags to footer.php for showing the sidebar, and performing the wp_footer hook.

I forgot to mention last post that, if you want to show a sidebar in your theme, you need to have another file called “sidebar.php” which contains the code for showing the user’s custom sidebar, or a standard sidebar if the user hasn’t set anything. WordPress then uses this file when you call get_sidebar to display the sidebar. An example of this file is:

<div class="sidebar">
<ul>
<?php
if(!function_exists('dynamic_sidebar') || !dynamic_sidebar()) {
?>
<li><h2><?php _e('Meta'); ?></h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a></li>
<li><a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>
</li>
<li><h2>Archives</h2>
<ul>
<?php wp_get_archives(array('type' => 'monthly')); ?>
</ul>
</li>
<?php
}
?>
</ul>
</div>

As you can see, the file first attempts to print out the user’s set sidebar (using dynamic_sidebar). In older versions of WordPress this function didn’t exist, so we need to test to make sure we’re using a version with dynamic sidebar support. If there is support, and the user has set up the sidebar with some widgets, dynamic_sidebar will return true to say a sidebar has been output. If it returns false, then a standard sidebar is displayed (most of the HTML in the above example).

The last two files we need to create (as part of this tutorial) are templates/singular.php and templates/multiple.php. Both these files can contain similar code. Sometimes, developers will usually just use the one “template” (and just include all their code in index.php). I personally can find that a little bit confusing, so split up the different types of post and page templates to make them more understandable. In both files, the major concept you’ll need to know about is “The Loop” (as the WordPress development team put it). This loop consists of two main parts:

  1. has_post()
  2. the_post()

Number one is the loop end check function, and is probably how WordPress developers came up with the name “The Loop” (most of the time you will use it as while(has_post()) in your code). This just checks if there’s another post available to be output. To actually move onto the next post (that has_post is saying can be displayed), you need to call the_post (number two above). This changes a global variable called $post to the next post in the list, and advances the system’s internal pointer to the next available post.

In my themes, I don’t worry about using while(has_post()) in templates/singular.php, since there is only one post to show. An example of a singular template page is as follows:

<?php
get_header();
 
the_post();
?>
<div <?php post_class(); ?>>
<h2 class="post-title"><a title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="post-meta"><?php
the_time(get_option('date_format'));
if(is_single()){
   the_author_posts_link();
   echo ' posted in ';
   the_category(', ');
}else{
   echo 'Posted by ';
   the_author_posts_link();
}
if(comments_open()){
   echo ' | ';
   comments_popup_link();
}
edit_post_link('Edit', ' | ');
?></div>
<div class="entry"><?php
the_content('Read more...');
$args = array(
   'before'           => '<div class="post-pages">Pages:',
   'after'            => '</div>',
   'nextpagelink'     => 'Next Page',
   'previouspagelink' => 'Previous Page'
);
wp_link_pages($args);
?></div>
<?php
if(is_single()){
?><div class="pagenavi">
<span class="previous-page"><?php
   previous_post_link('%link', '&laquo; %title');
?></span><span class="next-page"><?php
   next_post_link('%link', '%title &raquo;');
?></span>
</div>
<?php
}
 
comments_template('', true);
?>
</div>
<?php
get_footer();
?>

At the top and bottom you can see get_header() and get_footer(). These two functions tell WordPress that we want the header.php and footer.php files created in part 1 to be included at those two places respectively. The second function call in this template is the_post, which (as I stated earlier) advances WordPress’ internal pointer to the next post, and sets $post to the current post. The rest of the code should be self-explanatory – post_class prints the class attribute for the post/page wrapper, the_title prints the post or title, the_time prints the current time (same type of syntax as php’s date function), the_content prints out the post or page content, etc.

Some functions that may not seem that intuitive may be “is_single”, “wp_link_pages”, and “*_post_link” (* being previous or next). The first one, is_single, is used for checking whether the current thing being looked at as part of the loop is a regular blog post or not. If it is, is_single will return true. The second function prints out page links for posts or pages that are longer than a single page long. Finally, *_post_link prints out a link to the previous or next post (respectively), allowing visitors to navigate between posts without having to go back to the user’s posts list.

The final part of the page that should be pointed out is comments_template. This function includes your theme’s comments.php file (yes, another file). I will show an example of this one at the end of this post. The second parameter of comments_template indicates whether WordPress should separate comments out by type (regular comments, pingbacks and trackbacks).

Now for an example of templates/multiple.php:

<?php
get_header();
 
if(have_posts()){
   while(have_posts()){
      the_post();
?>
<div <?php post_class(); ?>>
<h2 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="post-meta"><?php
      the_time(get_option('date_format'));
      if(is_single()){
         the_author_posts_link();
         echo ' posted in ';
         the_category(', ');
      }else{
         echo 'Posted by ';
         the_author_posts_link();
      }
      if(comments_open()){
         echo ' | ';
         comments_popup_link();
      }
      edit_post_link('Edit', ' | ');
?></div>
<div class="entry"><?php
      the_post_thumbnail();
      the_content('Read more...');
?></div>
</div>
<?php
   }
?>
<div class="pagenavi">
<span class="previous-page"><?php
      next_posts_link('&laquo; Older Posts');
?></span><span class="next-page"><?php
      previous_posts_link('Newer Posts &raquo;');
?></span>
</div>
<?php
}else{
?>
<div class="page">
<div class="entry"><?php
   printf('No posts were found. Why not <a title="Go Back" href="%1$s">go back to the last page</a>?', $_SERVER['HTTP_REFERER']);
?></div>
</div>
<?php
}
 
get_footer();
?>

As you can see, this file is pretty much the same as templates/singular.php. The only major differences are the use of an actual loop (while(has_post()) as well as the_post()), using the_permalink() in the link element for the title, showing post thumbnails (with the_post_thumbnail()), not including post pages for longer posts, using *_posts_link for jumping between pages, and not including comments_template. You’ll also notice the use of an if/else around The Loop. This is in case there are no posts available for the archive being displayed.

You may be wondering why the previous page uses next_posts_link, and the next uses previous_posts_link. This is because WordPress puts older posts on higher numbered pages, and names those higher numbers as “next”. So, for my themes (and this example), I’ve chosen to flip them to make it look a bit better on the archive pages.

The final template file to populate is comments.php. This one is fairly short if you use WordPress’ default output features and form. I’ve recently started using this in my own themes:

<div class="comments">
<?php
comment_form('comment_notes_after=');
if(have_comments()){
?>
<div class="comment-list" id="comments">
<h3>Previous Comments</h3>
<?php
   wp_list_comments('style=div&max-depth=3');
   if(paginate_comments_links('echo=0')){
?>
<div class="commentnavi">
<?php paginate_comments_links(); ?>
</div>
<?php
   }
?>
</div>
<?php
}
?>
</div>

This example first outputs the comments form (without any notes, given by the parameter), Then checks if there’s any comments to print before printing a title and using the standard WordPress comments output mechanism (wp_list_comments). I then check if there’s any page links (using the function that outputs them, since there’s no other way to check), and output them if there are more pages.

Now to get the theme working properly, my example (and most of my themes) gets index.php to include templates/singular.php, and all archive type pages to include templates/multiple.php. Once all these files are done, the theme should appear and look pretty close to how you designed it. You may need to tinker with your styles a little, and add in any classes that WordPress itself uses.

You’re pretty close to finished now. There is one more file that needs to be created if you are using the sidebar and want to allow a custom navigation. Since this post is already pretty long, I will leave that for another post in another couple of days time.

If you have any problems up to this point, please leave a comment.
Robert