L.J. ver.1.5 – Tinkering with Wordpress

13 Oct 2004

Index.php – More Posts, Less Space

The first thing most people will notice on the new home page is the addition of the Recent Entries table. The table format allows me to show all the relevant details of more new posts in less vertical space than the old ‘heading and excerpt’ format. If any Wordpress users want to see how I went about manipulating The Loop, I’ve attached a heavily stripped down version of the code below. It’s very simple, but that was my plan this time around – to stop ignoring the bleeding obvious methods in favour of more elegant, but essentially unnecessary solutions.


<h2>Latest Entry</h2>
<?php 	$cow=0;  // create our counter
 		$cowsleep=6; //tell it when to stop
if ($posts) : foreach ($posts as $post) : start_wp(); ?>

<?php if($cow==0) { ?>
	<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
	<?php the_excerpt(); ?>
	<a href="<?php echo get_permalink(); ?>">Continue reading <?php the_title(); ?></a>
	<hr />
<?php } ?>
<?php if($cow==1) { ?>
	<table summary="Recent journal entries from all categories">
		<caption>Recent Entries</caption>
		<thead>
		<tr>
			<th scope="col" class="title">Title</th>
			<th scope="col">Date</th>
			<th scope="col">Comments</th>
		</tr>
		</thead>
		<tbody>
<?php } ?>
<?php if($cow!==0) { ?>
		<tr>
			<td><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></td>
			<td><?php the_time("M j, Y") ?></td>
			<td><?php comments_popup_link(__('0'), __('1'), __('%')); ?></td>
		</tr>
<?php } ?>
<?php if($cow==$cowsleep) { ?>
		</tbody>
	</table>
<?php } ?>
<?php $cow++; //increase counter value by 1 ?>
<?php endforeach; else: ?>
			<p>Sorry, something's gone awfully wrong... </p>
			<?php //custom error reporting ?>
<?php endif; ?>

The problem I over-intellectualised the most was clickable dates — month and year names that point to the archive of that period. As soon as I remembered the most important part of permalinks, (they never change) I whipped up a quick and messy solution in a minute.


<a href="<?php echo get_settings('siteurl');?>/journal/<?php the_time("Y") ?>/<?php the_time("m") ?>/" title="Archive for <?php the_time("F") ?>"><?php the_time("F") ?></a>
<?php the_time("j") ?>,
<a href="<?php echo get_settings('siteurl');?>/journal/<?php the_time("Y") ?>/" title="Archive for <?php the_time("Y") ?>"><?php the_time("Y") ?></a>

All I have to do is include that script where ever I want a post date to appear and it will do the rest using nothing more than the the_time() function and the domain name. Not very portable, but considering I would never intentionally change the URL structure it shouldn’t be a problem.

Mini Posts

Part of the reason I wanted to get more posts onto the home page is that I would like to start including mini-posts amongst the more lengthy articles. The quickest way I could think of to account for excerpt-less posts was using Scott Reiley’s highly versatile get-custom plug-in. By adding the custom field of short and assigning it the value of true, I can check for this on the fly and change the mark-up accordingly.
Here is a quick example; changing the text of the permalinks.


<?php if (c2c_get_custom('short')=="true") { ?>
	<a href="<?php echo get_permalink(); ?>" title="Permanent Link">Permalink for <?php the_title(); ?></a>
<?php } else { ?>
	<a href="<?php echo get_permalink(); ?>" title="Read entire article">Continue reading <?php the_title(); ?></a>
<?php } ?>

Minor Tweaks

There have been a fair few minor changes, including ditching the graphic submit buttons and reverting to the trusty submit input element. Hopefully you like the new alterations -- let me know if there’s anything else you would like to see changed. In other news, I finally have a post for the Lab section of this site; hopefully I'll find the time to finish it off later in the week.

Filed under: ,

10 Comments

  1. Chris Gwynne:

    Liking the new look. Definitely a lot more organized than what you previously had it.

    Another lil bug I’ve just found. If you hover over your XML button you’ll get an underline all the way across the page. (FireFox, Windows). Few CSS issues too.

    Looking forward to your lab post.

  2. Geoffrey Sneddon:

    I prefered the long homepage… Maybe that’s just me…

  3. Andrew:

    Thanks for picking that up Chris! I had spelt colour correctly in my print.css :-O
    The second error, relating to media=”screen, projection” is an error in the validator. Comma deliminated lists of supported media is correct according to the spec — I wonder why they didn’t include it in the validator??

  4. Geoffrey Sneddon:

    Andrew: What happens if you remove the space? Would that make it validate? You’re also not the only one who’s spelt colour correctly…

    Noticed that all names are bold now… Have you removed the :visited {text-decoration:none}?

  5. Andrew:

    Yes Geoffrey, I have removed the :vistied {font-weight:normal;} — I have also taken the liberty of editting your comment for you…

  6. Geoffrey Sneddon:

    It was one of those comments which I would’ve edited on a forum… the only problem is you can’t here, or on any WP install

  7. Andrew:

    No probs at all mate — there have been many occassions when I wish I could edit my comments on other people’s blogs. You can always email me if you want something edited ;-)

  8. Tom Loudon:

    I set up the system you show above while getting my site working.
    The problem I found was that it doesn’t work if you have less posts than the number specified in $cowsleep. I know that this is not a problem that you or anyone else will worry about.

    While I was setting it up I started wondering if wordpress offered any way to do what you show. It does, WordPress Wiki – get_posts will do the job with less code.

    Hope that is of use.

    I like the site by the way. Keep the useful stuff coming.

  9. Tom Loudon:

    Sorry the link didn’t work in the last post. WordPress Wiki – get_posts.

  10. Andrew:

    Thanks for that Tom, just in time to be added to the update list for the next version of this site.