Posts in the category "Tweaks".

Modifications to the WP templates etc. This is a ‘note to self’ category, but maybe you’ll find something you’ve wanted to change in the regular WP, too.

Exclude pingbacks from comments RSS

A weird character in Jafer’s pingback title (or site title, actually) messed with my comment feed, so I decided to exclude pingbacks (as I won’t allow trackbacks) from my comments feed. I tweaked wp-commentsrss2.php file (found in the root WP folder), around lines 36 and 44:

AND $wpdb->comments.comment_approved = ‘1’ AND $wpdb->comments.comment_type != ‘pingback’

Comments are of type ” (null) and trackbacks are ‘trackback’, so I think putting comment_type = ” would work as well and you wouldn’t have to put a != (not equals) for both pingbacks and trackbacks.

[edit: May 9] That was a short-lived hack. WP1.5.1. solves the problem with odd characters causing grief for RSS feed readers [/edit]

Tweaking Since Last Visit hack

I don’t use the JavaScript version of Alex King’s Since Last Visit hack/plugin because I don’t like to depend on JS. And I didn’t even get it working back when I tried it out :laugh:

After keeping the comment referred to in my previous post I noticed that the targetted post was showing new comments. So, I added a requirement to the database query in function ak_new_comments: and comment_approved not like 'spam' making it say

if (isset($ak_last_visit)) {
 $last_visit = date(“Y-m-d H:i:s”, $ak_last_visit);
 $comment_date = $wpdb->get_var(“SELECT MAX(comment_date)”
 .”FROM $tablecomments ”
 .”WHERE comment_post_ID = ‘$post_id’ and comment_approved not like ‘spam’
 if ($comment_date > $last_visit) {
  echo $html;

around line 178. No more ghost comments.

(Database studies came in handy, yet again.)

Serene Saturday

I was going to trackback the Comment text plugin page, but I noticed the plugin author had noticed the missing quote problem and corrected it. I, however, hacked it together myself. It just needed some complexity to the code that builds the comment links:

<!-- First link, to get a custom text, around line 50 -->
echo '<a href="' . get_permalink() . '#comments' . '">' ."$text ($number)" . '</a>';
<!-- Second link, to get default text, around line 54 -->
echo '<a href="' . get_permalink() . '#comments' . '">Comments'. "($number)</a>";

Another thing, I’m making a site for Amadeus :)

Ehm… what was I thinking: “serene”? I’ve been playing Painkiller which is quite a hectic game. I’ve slaughtered hell’s boogers that attack me in hordes. Not even close to serene! Oh, and while I was making the header image + design for the Ami site, the computer suddenly shut down and I found out that a safety fuse had blown out. The fridge and oven in our kitchen were without electricity as well as our neighbour’s kitchen. Oh, and don’t forget our computers.

Despite the boogers (I know booger is the stuff that comes out of one’s nose, so?), or because of them, Painkiller is a very nice game. Somber. Nicely gruesome. I was a bit worried how it’d play on Simon because the minimum specs was 1,5 Ghz and I have 1,4. The game runs like a charm, however, and I didn’t even have to lower the performance settings. The graphics are amazing! A starry sky at the cemetary is very beautiful — until the skeletons attack.

The game is so hectic that I can’t play it for long without starting to feel a bit of motion sickness or something. Maybe I should lower the head bob setting.

Mutating menu

I’m making my right-hand side menu a Tabbed one. The idea behind it is that I can put context-dependent links (subcategories when on a category page, dates when in monthly archive, all static pages when on a static page, or something like that). There aren’t any of those yet, maybe I’ll have time to tweak that during the weekend (although I’m translating a paper for Dad — well, I won’t be doing that in the evening I think). Yup, that’s all.

Show all sesame!

I suddenly noticed the admin’s post editing page doesn’t show all the posts. It stupidly is affected by the number of posts shown on the blog’s index page which certainly isn’t the way it should be.

On the WordPress forums I could find some old posts on the subject and a person there said he would post a patch when he gets around checking it.

Well, I tried his idea (copy-pasting a code snippet from post.php to edit.php to reset some variables) but I couldn’t get it working. So, I made an “unprofessional” patch.

I haven’t had more than 50 posts per month (that’s how the posts are categorized) so I added a variable to show 50 posts “per page” (there aren’t any pages, really). This is at the very top of edit.php:

$title = __('Posts');

As the forum posts suggested, you might have to do something about the edit-comments.php too, but I have exactly 10 comments so far so I don’t know if all of the comments will show.

Category and archive droppings

In the attempt to shorten the menu, I decided to put the lists of monthly archives and categories into drop down menus. I just realized that in time they will (at least the monthly archives) get longer and longer and longer…

So, my first problem was that I’ve made a hidden category for static pages and it would show on the menu if I used WP’s built-in dropdown_cats tag.

Luckily, Ria at Typed by has made a Drop Down Cats Plugin with ability to exclude. What’s nice about it is that it a) formats subcategories differently from parents (indented with a hyphen), and b) it includes a post count parameter.

Archive tag (wp_get_archives) has an option to format the list of archives as an option list. You just need to build a drop-down menu function around it. Thus, as found at the WordPress forums
(remove the spaces after dots in “window.location=” if you’re going to cut-and-paste that — I needed to separate the words because it wouldn’t wrap nicely)

<form name="archiveform" action="">
  <select name="monthly_arch" onchange="window.location = (document. forms. archiveform. monthly_arch[document. forms. archiveform. monthly_arch. selectedIndex].value);">
    <option selected>Monthly archives</option>
    <?php wp_get_archives('type=monthly&format=option'); ?>

It includes a little JavaScript, but I don’t know if that can be avoided. I’m disappointed to notice that formatting the archives as options is not compatible with showing the post count.
In the same thread there was a solution to that too. It involves a little tweaking (or correcting…) in template-functions-general.php, function get_archives_link around line 180, changing

else if ('option' == $format) {
return '<option value="'.$url.'">'.$text.'</option>'."\n";


else if ('option' == $format) {
return '<option value="'.$url.'">'.$text.$after.'</option>'."\n";

Layout worries revisited: The solution

First of all, Happy Mulder’s Birthday!! He’s 43 today. Chris Carter, whose b’day it really is, is 48.

Now that I’m going crazy with formatting my code snippets and doing tiny icons to appear in the bottom right corner of the snippet box, I’m going to post a summary on the layout trick I learned in an article at A List Apart. The basic structure of a page is

<div id="wrapper">
  <div id="container">
    <div id="content">
  <div id="sidebar"></div>
  <div id="clear">&nbsp;</div>
<div id="footer"></div>

I.e. container, sidebar and clear-div go inside the wrapper. Clear-div makes sure the footer doesn’t clash with the menu.
Then, in the css part you specify

#container {
  width: 100%;
  float: left;
  margin-right: –menu widthpx;
  margin-right: menu widthpx;
#sidebar {
  width: menu widthpx;
  float: right;
  height: 0;
  clear: both;

This places the menu on the right hand side.

Tweaking the calendar

My calendar didn’t have a link to the current month, so I added it. There’s a function called get_month_link(year,month) which returns the URL to a monthly archive page (not the link). So, I put it in some <a> tags:

<caption><a href="'.get_month_link($thisyear,$thismonth).'"><img src="'.get_settings('siteurl').'/image location/'.$month[zeroise($thismonth, 2)].'.gif" /><img src="'.get_settings('siteurl').'/image location/'.date('Y', $unixmonth).'.gif"></a></caption>

Of course, if you don’t have images in place of the original texts, you just put the link part around what there is in the <caption> of the calendar table. Basically it’s

<caption><a href="'.get_month_link($thisyear,$thismonth).'">whatever you do to get the month and year</a></caption>

Ironing and folding and sorting by date

I added the Nicer Archives code snippet from WP Wiki. I tried to use the “upgraded” versions of it (from Weblog Tools Collection) but they borked — big time.

When you enter the page, it shows the posts of the current year. Then you can sort the posts by date, title, or category; ascending or descending; and from all years or one year at a time (there is only one year, for now). The original script had a possibility sort by author but because there’s only me, I commented it out.

Time format is date.month.year.

On to the archives »

The calendar showed as January 2004 so I started to look for a way to remove it. Easier said than done. Well, not really, but I didn’t think of echoing the variable in my if-test to see what it’s out put was. This is what I wrote (first):

<?php $thispage = $_SERVER[‘HTTP_HOST’].$PHP_SELF;
    if ($thispage != ““) { ?>
     <!-- CALENDAR -->
     <li id=”calendar”>
        <?php get_calendar(); ?>
<?php } ?>

http_host + php_self return the url of a php page a without the http (as that’d be the protocol)

Then I tried what $_SERVER[‘REQUEST_URI’] does and it echoed the path without the host. Nifty. Thus, I changed the code to

<?php $thispage = $_SERVER[‘REQUEST_URI’];
    if ($thispage != “/blog-folder/pagename.php“) { ?>
     <!-- CALENDAR -->
     <li id=”calendar”>
        <?php get_calendar(); ?>
<?php } ?>

[edit: Nov 22/Dec 15, ’04/Jan 5, ’05] I had an oddly titled post which messed up the archive. Well, not exactly *mess* but because it had an less-than sign at the beginning it was archived under L, but first alphabetically. After some testing, I figured out how to prevent this. From the WP Wiki I found a function sanitize_title_with_dashes which I used in the archive code, this is in the function archive_header: This worked when my odd titles included only one starting with A. But when there was one with D, I noticed the code didn’t work. Why? Because it compares the first letter if the current title to the previous one and the query sorts the odd titles at first. Well, I took another approach to this. All odd titles will be categorized under # (I know it means ‘number’ but here it’s just some non-alphabetic character). A new try, a * I had in one of the titles wouldn’t be recognized, probably because the line starting with preg_match matches only letters and numbers, so I changed that to match any one character (at the beginning). Hopefully this will prove working with my strange titles…

elseif ('title' == $orderby) {
preg_match('/.{1}/i', $post->post_title, $match);
$thisletter = ucfirst($match[0]);
if (!ctype_alpha($thisletter)) { $thisletter = '#'; }
if ($thisletter != $previous) {
$output .= "<br/>".$thisletter;
$previous = $thisletter;

The highlighted part checks if the first letter of the title is NOT an alphabetic character, if it’s true that it’s NOT one, the letter will be a ‘#’. Now all the odd titles will be grouped at the beginning of the list of titles (or end if the order’s descending) . [/edit]

All new all things me

The redesign of all things me is finally done! Now I’m just waiting for the domain to start working to the right direction. (aaagh, 1 week free trial period and the domain won’t be registered before I pay the bill — but they won’t send me the bill!!)

So, I’ve changed from green/purple to purple (or lilac or violet — I don’t know!). I was planning to have my “colour depth of three” (black, white, purple) on the site but black was so bright!! So I made it a little “foggier” (#444444). I’ve used Harrington font in the pictures. I don’t know where that splash came from; I was looking for a nice bullet (which, in the end, I didn’t use) and then I decided to add it in front of the post titles to separate them more clearly when there’re several posts in one day.

The layout is flexible. That means the text is as wide as it can be (minus the menu). I used to have it at max 760 pixels which I — on a 1024×768 screen — didn’t like but I had to think about you little people. I mean, people with little screens — whoops!

Now that I have a proper domain I’ve enabled ping/trackbacks (not yet on all posts cause I have to click through them all dammit). I said bye-bye to category pictures. They just didn’t fit anywhere. Hmm… I *could* put them on a post’s individual page.

On to another topic. I finished reading Dark Tower VI: Song of Susannah on September 27. At 4:40 am. Ssshhh, don’t tell anyone! Now I’m waiting for DTVII to arrive in the bookstores. It was published on 21st and when I went to ask when I could expect it to be on the shelves they said “in two weeks”, so I’ll probably check it this week (as I have to drag myself to the center on Friday — 2 months of work starts, again) and then, naturally, next week.

Now I’ll add the category image thingy…

I also changed from Pagination to "vBulletin Style page navigation".

Yesterday night I was glued to the screen reading a blog (Myrskymurmeli) that had a convenient page navigation (hmm… actually I think it’s the default WP navigation which I’d removed to enable ScriptyGoddess’s Pagination… anyway) and I read the whole blog to the very first entry… thank gawd there wasn’t a lot more entries — I would’ve been stuck to the screen till the wee hours.

I’m starting work tomorrow… I’ll be working for 3 months’ worth and doing as-long-as-I-can/want-days until I’ve filled the required hours. I’ll be working till the end of spring I bet ;)