Left Justified

Feeds

L.J. ver.1.5 - Tinkering with Wordpress

| October 13, 2004 | Category: Design

Ever since this site launched there have been elements of my Wordpress setup that I haven’t been happy with. The most notable being:

  • Most pages had to scroll far too much to show the content, especially the home page.
  • Every post required an excerpt, making quick posts difficult - not to mention the fear of filling the home page with non-design posts.

Yesterday I realised that I had been approaching these problems all wrong; over complication of simple goals had taken control. Today I fixed the problems.

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.

  1. <h2>Latest Entry</h2>
  2. <?php $cow=0; // create our counter
  3. $cowsleep=6; //tell it when to stop
  4. if ($posts) : foreach ($posts as $post) : start_wp(); ?>
  5. <?php if($cow==0) { ?>
  6. <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
  7. <?php the_excerpt(); ?>
  8. <a href="<?php echo get_permalink(); ?>">Continue reading <?php the_title(); ?></a>
  9. <hr />
  10. <?php } ?>
  11. <?php if($cow==1) { ?>
  12. <table summary="Recent journal entries from all categories">
  13. <caption>Recent Entries</caption>
  14. <thead>
  15. <tr>
  16. <th scope="col" class="title">Title</th>
  17. <th scope="col">Date</th>
  18. <th scope="col">Comments</th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <?php } ?>
  23. <?php if($cow!==0) { ?>
  24. <tr>
  25. <td><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></td>
  26. <td><?php the_time("M j, Y") ?></td>
  27. <td><?php comments_popup_link(__('0'), __('1'), __('%')); ?></td>
  28. </tr>
  29. <?php } ?>
  30. <?php if($cow==$cowsleep) { ?>
  31. </tbody>
  32. </table>
  33. <?php } ?>
  34. <?php $cow++; //increase counter value by 1 ?>
  35. <?php endforeach; else: ?>
  36. <p>Sorry, something's gone awfully wrong... </p>
  37. <?php //custom error reporting ?>
  38. <?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.

  1. <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>
  2. <?php the_time("j") ?>,
  3. <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.

  1. <?php if (c2c_get_custom('short')=="true") { ?>
  2. <a href="<?php echo get_permalink(); ?>" title="Permanent Link">Permalink for <?php the_title(); ?></a>
  3. <?php } else { ?>
  4. <a href="<?php echo get_permalink(); ?>" title="Read entire article">Continue reading <?php the_title(); ?></a>
  5. <?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.


  1. 1
    Chris Gwynne said:

    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.

    Comment posted on:
    11:18 pm, 13th of Oct 2004
  2. 2
    Geoffrey Sneddon said:

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

    Comment posted on:
    4:07 am, 14th of Oct 2004
  3. 3
    Andrew said:

    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??

    Comment posted on:
    7:45 am, 14th of Oct 2004
  4. 4
    Geoffrey Sneddon said:

    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}?

    Comment posted on:
    5:30 am, 15th of Oct 2004
  5. 5
    Andrew said:

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

    Comment posted on:
    12:47 pm, 15th of Oct 2004
  6. 6
    Geoffrey Sneddon said:

    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

    Comment posted on:
    3:24 am, 16th of Oct 2004
  7. 7
    Andrew said:

    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 ;-)

    Comment posted on:
    10:24 pm, 31st of Oct 2004
  8. 8
    Tom Loudon said:

    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.

    Comment posted on:
    12:08 am, 2nd of Dec 2004
  9. 9
    Tom Loudon said:

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

    Comment posted on:
    12:10 am, 2nd of Dec 2004
  10. 10
    Andrew said:

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

    Comment posted on:
    11:56 pm, 5th of Jan 2005

Have Your Say

Sorry, comments are closed on this post.