Mostly about my amusement

Category: Geek (page 23 of 36)

Threaded comment are fixed

Opensource software is best.

Using a comment callback function in WordPress 2.7, I was trying to customize the threaded comments and ran into a problem. So I left a comment on Jeremy’s blog. He contacted me and was able to find the problem and provide a fix.  His post has been updated with that small change and it’s all good.

Very cool, you can’t get that kind of response from any software company. I’ll keep playing around with the comment format, but now I can implement anything I like and take full advantage of the threaded comment feature.

Odd way to end a vacation

I’ve been on vacation since right before Christmas and have enjoyed the time off. Monday I go back to work all refreshed and ready to go.

After our New Years Eve party, I spent the day doing somethings that had meant to do for a while: PHP coding for my WordPress blog. My PHP fu is not that great but this is how I learn and as hobby’s go, it’s almost productive. Starting with easy ones and working my way down, the list looks like this.

1. Clean up my theme directory.

I make changes to my theme all the time and left junk in the theme directory. There is junk in there from plugins that I was experimenting with, looks that I was trying to accomplsh, etc. I can’t remember it all but I know what I need to keep and my backups are good and current.

2. Setup my Flickr badge as a WordPress plugin to put a widget in the sidebar.

I was using a text widget and hard coded the CSS into my theme’s header.php so that the page would validate properly. That worked but if I changed themes, the styling went out the window.  I had wanted to see how to create a widget plugin that inserted the CSS using the wp_head action. By looking at existing plugins I saw how and it’s not hard at all.

Now I can keep the widget no matter which theme I choose and it always validates. Next up to add options in the widget. I’m looking at the Flickr Widget to see how it’s done there. Having GPL’ed code available to examine makes life so much easier.

I want to get an options page just for giggles; I don’t plan on distributing the code since I’m re-using Flickr’s code from here.

3. And now the big one: Fix my comment CSS and get WordPress 2.7 threaded comment callback working properly.

WordPress 2.7 comes with the option of using threaded comments and getting the default output just needs these lines:

<ul class="commentlist">
<?php wp_list_comments(); ?>
</ul>

This produces good valid XHTML output and all that is required is to style it anyway you want. With some CSS I get this:

comment-thread

It’s really easy to do and between Otto and Chris Harrison’s posts, getting it looking good is simple. If you want to learn then visit those two sites and start playing with your theme.

Now if you want to explicitly control the output for threaded comments, you need to use a callback as outlined in Jeremy’s post. I’m adding a comment count and trying to keep the look close to the original theme’s styling. By inserting the theme’s original comment code I can maintain the look.

In my comments.php file I comment out the old line and add one to use the callback.

<ul class="commentlist">
<?php // wp_list_comments(array('avatar_size'=>40,'reply_text'=>'Reply to this comment')); ?>
<?php wp_list_comments('callback=custom_comment'); ?>
</ul>

In my function.php file I’m adding this code.  Be warned, I am not a PHP programmer and if anyone sees something really gross please feel free to criticize. The $cmtorder is more of a placeholder and I’m not using it yet.

<?php
function custom_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<?php global $cmtcount; ?>
<?php
$pageadd = 1;
if(get_option('page_comments')) :
$page = get_query_var('cpage');
$pageadd = (get_option('comments_per_page') * ($page - 1)) + 1;
$cmtorder = get_option('comment_order');
endif; ?>

<li id="comment-<?php comment_ID() ?>" class="<?php echo tj_comment_class() ?>">
<div class="commentNumber">#<a href="#comment-<?php comment_ID() ?>"><?php echo $cmtcount + $pageadd; ?></a></div>
<div class="comment_mod">
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
</div>

<div class="comment_text">
<?php comment_text() ?>
</div>

<div class="comment_author">
<?php if (function_exists('get_avatar')) { ?>
<?php echo get_avatar($comment, '32'); ?>
<?php } ?>
<p><strong><?php comment_author_link() ?></strong></p>
<p><small><?php comment_date('j M y') ?> at <?php comment_time() ?> <? edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?></small></p>
</div>
<div class="clear"></div>

<?php echo comment_reply_link(array('before' => '<div class="reply">', 'after' => '</div>', 'reply_text' => 'Reply to this comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ));  ?>
<?php $cmtcount = $cmtcount + 1; ?>
<?php } ?>

This gets the comments formatted close to the theme’s original comments but adds threading.  I added the comment count as a “why not?”  If you turn on paged comments the comment counter still work. I have not worked out changing the order yet, I’d like to see it working in reverse order if set.

comment-thread-callback

The code is a bit ugly and I’ll clean it up later. It works and I’m not getting and errors in my log so I’m happy for now. The CSS is good and the generated XHTML code is valid.

My only problem is that the javascript reply to comment box is not working exactly the way I want it to.

When you click on the “Reply to this comment” link, the comment box show up outside of that comment’s <li> … </li>. This is probably due to how I’m using comment_reply_link() but right now the codex is a little bit sparse on that topic. I’ve looked at the source code and by changing the parameters, I do get different results, just not the results I want. If I don’t use the callback, the comment box appears within that comment’s <li> … </li>.

I’ll keep playing with it and will be switching them back and forth until I like the output.

Oh. That many pictures.

Today is slow and almost all of our shopping is done. So I am going through my photos this evening and notices something.

I purchased my Nikon D60 in May 2008 and have been using Photoshop Elements since then. My external 1TB WorldBook is where I keep my photos and PSE keeps a tally of all the photos in it’s catalog.

PSE file counter

10,272 pictures.  From before May 2008 there were less than 300. Wow. Most of them are disposable and will never be shared but… wow.

WordPress 2.7 is shaping up nicely

I’ve had this blog on WordPress 2.7-beta using SVN for a while. So when it went release candidate, all I had to do was another just run another “svn up”.

The comment enhancements are cool and Otto provided a good write up for modifying the files to take advantage of it. Implementing it and staying XHTML valid was not a problem.

My problem was that without styling it, the new comments looked like crap.

Lucky on the WordPress support forums I found that Chris Harrison mapped out all the CSS for the comment list. Adding the elements that he provided let me easily make changes and get the comments close to the original look.

I still need to play around with it but so far I’m satisfied with the results.

Dead Xbox 360 MTU issue

For months my Xbox 360 has been complaining about the MTU being too small on my Internet gateway. This meant no updates and Xbox Live stopped working. I’ve been busy so I did not give it much thought.

My brother Alek bought a new one  for his apartment and hooked it up at my house.  I figured that the MTU problem was an issue with my old Xbox 360. Naturally it wasn’t.  His had the same problem so I looked at my Linux gateway.  Running ifconfig on my server showed me that the MTU on the external interface was set to 576.

How did that happen? I thought it defaulted to 1500. I ran the command “ifconfig eth1 mtu 1500” and that fixed the problem right away.  On my openSUSE server I edited the file /etc/sysconfig/network/ifcfg-eth1 and made the MTU line read MTU=’1500′. This way when my box reboots the MTU setting should go to 1500.

After that was done, Alek was able to download the “new Xbox Experience”.  The irony is that Friday night my Xbox 360 finally gave up the ghost and died.  It’s out of warranty so I’ll be heading to Best Buy to get the holiday bundle.

The iPhone 3G

iphone-3g-desk

I’ve had the iPhone 3G for a week now and have come to one inescapable conclusion:

I need to buy a watch.

The iPhone 3G is well designed and easy to use.  The screen is larger than my old BlackBerry Pearl but not too large. The built in applications are generally okay but a little on the “more is less” side. For example, the e-mail client is very functional.  I am able to have my mail delivered using my own SSL based SMTP AUTH relay (open SMTP relays are criminally stupid) and the client works well with my own IMAPS server.  Using IMAPS I get full access to my mail folders on my phone (finally!) via an SSL connection. I can view attachments such as PDF and Word documents with ease.  But the e-mail client looks sparse and drab.  It works well but could be spruced up a little.

The web browser is Safari, plain and simple.  It’s good but given the screen size I find myself visiting websites that support the iPhone directly.  Both CNN and Newsweek have good mobile websites and all of Google’s web sites are built to work well in the iPhone.

You can’t run multiple applications at the same time, so instant messenger is pretty much useless.  The only thing that will run in the background is the iPod application for playing music.  That works out for me since I read RSS feeds in Google Reader while listening to music.

The built in assisted GPS is great and I have enough apps that will let me find the nearest you-name it store.  I have not played with Google Earth on my phone but I’m told that it is insanely good and fun to play with.

Applications are plentiful and readily available from the app store. The price ranges from free to around $15, with most being less that $3.  I can recommend TouchTerm as an adequate ssh client and everyone should buy the addictive Bejeweled 2 game.  The free Facebook app is really easy to use. I have not been tempted to jail break my iPhone because I have no need to.  Except for IM, everything I want to do works.  Why hack my phone?

The video capabilities is surprisingly good.  If you have a collection of videos on your PC (oh, for talking purposes, say English subtitled Anime) you can convert them for using on the iPhone with WinFF. It’s a GUI wrapper for ffmpeg and works well.  One thing to watch out for is the audio.  Set the optional arguments in WinFF for “-async 1” and this will fix any audio sync problems.

My old phone only went as fast as EDGE so to me the 3G network is really fast.  On my first day using the iPhone and firmware 2.1, I took the LIRR train to the office.  I listened to the radio via the 3G network using an iPhone app.  I had to restart the stream twice but that’s pretty good for a 55 minute train ride.  In Manhattan I listened to the radio via the 3G network all week as I walked to Penn Station.

The iPhone 3G comes with an A/C adapter and a USB cable.  No software CD, no docking station, nada.  That’s generally OK as iTunes is available on Apple’s web site and you can buy lots of accessories.

Tonight I went back to the Apple Store and bought another USB cable and an Air Jacket set.  This contains a clear hard plastic case that protects the shiny back of the iPhone and a film for the LCD cover.  I’m using the anti-glare one and it works really well.  No residue and all I did was clean the screen with my lens cloth and used the pre-installation film for picking up any dust.  This second visit to the Apple Store makes it official; I am now one of the Apple Undead (a repeat customer).

Oh, and the reason I need to buy a watch?  With my old BlackBerry I would use it as a time piece.  The iPhone is slightly too large to keep pulling out of my belt clip to do that. So I need to buy a watch.