Nearly four years ago, I wrote a tutorial on how to access the serial (and parallel) port under Windows XP. When I published the tutorial and the useful (self-written) Pascal libraries on this site, I didn’t know how much response I would get from the Internet community. As a matter of fact, my tutorial — and even more important — my libraries were the only ones really working on XP and the archive containing both the tutorial and the sources got quite popular.
A half year later, while I was working on my webserver, I accidently deleted that archive. A few hours later, my whole harddrive crashed, leaving behind nothing but useless file fragments. Since then I’m constantly getting mails to reupload (or rewrite) the tutorial and the libraries.
Finally, I decided to give it a try and rewrite it, in order to satisfy those who still code serial port accessing software on XP. (Or, if you are one of those lucky ones who still have my tutorial on their harddrive (due to a better use of backup systems), I ask everyone to send me the named files to my mail address).
When I started developing Wordpress themes, the output format of functions like wp_list_pages and wp_list_categories seemed always ugly to me. Having nested ul-tags and strangely formatted HTML code was not how I pictured me writing a nice, simple and clean layout. So I decided to write my own implementations of those functions, in order to fit the output to my needs. (Okay, “my own implementations” means in this context, I just put together some PHP code.)
Whether this will be helpful for you or not, I decided to share the small amounts of code with you, in case you want to customize your Wordpress functions, too. Some might stick to the normal functions, some might use the following PHP lines in order to manipulate the data the way they need it.
Let’s start with the customized wp_list_pages function.
<ul>
<?php global $post; $myposts = query_posts(array('post_type'=>page,'orderby'=>title,'order'=>ASC)); ?>
<?php foreach($myposts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
In the same way, the following code will list all categories.
<ul>
<?php $categories = get_categories($args); ?>
<?php foreach($categories as $category) : ?>
<li><a href="<?php echo get_category_link($category->term_id); ?>"><?php echo $category->name; ?></a></li>
<?php endforeach; ?>
</ul>
Finally, the standard formatting of the comments function wp_list_comments can be customized this way:
<?php
function customize_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<div class="comment">
<div class="comment-author">
<?php echo get_avatar($comment, $size='48'); ?>
<?php printf("%s says:", get_comment_author_link()); ?>
</div>
<div class="comment-meta">
<?php printf("%1s, %2s", get_comment_date(), get_comment_time()); ?>
</div>
<div class="comment-text">
<?php comment_text(); ?>
</div>
</div>
<?php
}
?>
Adding this code to your functions.php allows you to use the callback hook of wp_list_comments.
<?php wp_list_comments("type=comment&callback=customize_comment"); ?>
Quite simple, isn’t it? Feel free to adapt these code snippets and mail me in case you have something to criticise or improve.
A few months ago I started thinking about hosting a blog. At first, the intention behind that idea was to share everything important to me with all those who are interested. As a self-taught programmer (and soon to be student of computer science), I saw myself able to publish at least some posts of a certain value. However, personal issues and school stuff forced me to rethink and close down deluxian.org several times.
Times change, and so deluxian.org finally will get all the intention I can share. I will publish some good articles about Wordpress Theme Development and some Ruby code snippets that I think are worth sharing. In which direction this blog will develop I am not so sure of. Wish me luck.