The days nemesis has been vanquished!

This might seem a bit lame to those who actually know what they’re doing, but I have been bashing my head against the wall trying to figure out how to grab and display more than one post in a category using the archive.php file.

I’m using the archive.php file instead of creating a specific category file because I want to keep the layout the same with the least amount of editing whenever I do need to make a change. Copy pasta maybe easy, but it soon gets tiresome and is needless extra hassle.

After some frantic “help!” posts on twitter (thank you @wpbeginner for responding!) and friendfeed plus a little searching of my own, all roads seemed to lead to this page in the wordpress codex.

Specifically, this solution:

<?php

$categoryvariable=$cat; // assign the variable as current category

$query= ‘cat=’ . $categoryvariable. ‘&orderby=date&order=ASC’; //concatenate the query

query_posts($query); //run the query

?>

Now, dumping this just before the while (have_posts()) : the_post(); line, ensuring you swap out ($query) with (’showposts=10&cat=’.$cat) will give you what you want – upto 10 posts of the category selected by the user.

Sadly, this will break the displaying of your tags, which simply won’t do! Off to the drawing board again!

My starter for ten was to try creating my own bunch of if statements to alter the query based on whether it was a category or a tag just before my while statement. No good, broke the whole page instead of just a specific functionality. Then a lightbulb flickered inside.

There’s already an if statement determining what to do based on the users actions right at the top… why don’t I just sneak them into there? I’m cutting down on additional if statements and making the code cleaner. So, I bodged together the code and got the following:

<?php if (have_posts()) : ?>

<div class=”item entry”>

<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

<?php /* If this is a category archive */ if (is_category()) { ?>

<h2 class=”pagetitle”><?php single_cat_title(); ?></h2>

<?php

$categoryvariable=$cat;

$query= ‘cat=’ . $categoryvariable. ‘&orderby=date&order=ASC’;

?>

<?php query_posts(’showposts=10&cat=’.$cat); ?>

<?php /* If this is a tag archive */ } elseif( function_exists(‘is_tag’) ) { if(is_tag()){ ?>

<h2 class=”pagetitle”>Episodes mentioning <?php single_tag_title(); ?></h2>

<?php

$tagvariable=$tag;

$query= ‘tag=’ . $tagvariable. ‘&orderby=date&order=ASC’;

?>

<?php query_posts(’showposts=10&tag=’.$tag); ?>

Hit refresh and began testing…. it works! No breaking, no spooling out the wrong info!

Check it yourself at http://dev.verticalslice.tv by clicking on “News” on the left and playing around.

Not bad for someone who only knows basic HTML and lacks any knowledge of how wordpress functions internally. Tho, as I said, it’s still prolly lame to those who actually know what they’re doing – but I’m not them, and this was my victory ;)

If you know of a better way of doing this or if this opens the site up to a vulnerability, please let me know in the comments.

Hmmm…

Well, last night I suffered the C:\ on my main rig corrupting, guess that explains why the system had gone a little wobbly before I tried to reboot it.

This means I’m spending the day on my macbook while I have the HDD connected to my server for a little data recovery using Arax Disk Doctor, which has saved my arse a few times now (at a reasonable price too! No, I don’t work for them nor do I get any kickbacks!).

So, everything I was working on needed to migrate to there which means I discovered something… the text editor that comes with OSX sucks balls. Seriously, it totally screwed up the html/php I was working on causing the development site for Vertical Slice that I was playing with to break and not load. So, off I went hunting for a real editor.

I finally discovered a free one (since there are so many simple apps that people are trying to charge $70 and upwards for on OSX, definitely a better ecosystem on windows and linux). The editor I eventually decided upon is called Smultron. Well worth grabbing a copy if you want to edit html/php on your mac without paying stupid prices.

Oh, yeah… I kinda let slip about the next bit of news. I’m working on my own site for Vertical Slice rather than using tumblr to power it. This way I’ll be able to control how things look. Sadly, I don’t have any skills with PHP and SQL so I went on the lookout for an opensource CMS that lends itself to vlogging and came up with nothing.

There’s plenty of them for creating video sharing sites, but nothing specifically for a vlog. So, having had some experience with wordpress and being unimpressed with podpress, I thought I’d get down and dirty with a basic wordpress site.

The result is a totally stripped down interface crying for some tarting up sitting over at dev.verticalslice.tv. I’m trying to learn how to pick out parts of a post and arrange them into the site in the order I want – which is proving to be a difficult task when you lack a brain capable of writing code.

At the end of this endevour, I plan to release the theme for free so that there is a theme out there for a simple vlog site without having to pay a fortune.

Why bother with this when tumblr is doing a good enough job? Well, partly because I’d love to have the freedom to mod the site as I wish and partly because a friend of mine is offering to host it for me since they’re starting up their own business as a GSP (Gaming Service Provider). Basically they’ll have some servers in a datacentre, set them up with game servers and then rent them out. They’re looking to launch the service soon. I’ll post a link when I can remember what he said they were called >.<

While I have been stuck on my macbook today, I have done a couple of things. The first is to throw my hat into the ring for the Rocketboom Talent Search

I think I’ve made a solid application and could certainly pick up where Joanne left off, though a little nagging voice in the back of my head is telling me “you don’t really stand a chance”. I guess we’ll see, I totally loved my time writing for them and feel I could add so much more than the other applicants, but then I would say that.. wouldn’t I? ;)

The second thing was to finally get my interview with the code monkeys finalised and uploaded. This was my first ever interview and was the first time for Adrian, the guy I interviewed, so we both had nerves, lost our trains of thought and plenty of giggles at the camera (which I had placed in a very poor location).

The important thing for me, at least, is that I have finally conducted one and learned a hell of a lot from the experience. I hope you won’t be too savage when you do watch it – you will watch it, won’t you? :P

So, aside from waiting to see how the talent search goes, I’m stuck with the horrors of reinstalling the OS onto my main system and setting it back to how I like it.

That’ll be 4 hours of my life I can’t get back again :(