Archive for February, 2006

WordPress RDF Source Makeover

Posted on February 22, 2006 in Websites, WordPress by Jeff Starr

Beautiful Source-Code Output, Part 1: Whip your WordPress RDF Code into Submission

Update: This article applies specifically to WordPress 2.0.2, but may be generalized to any WP 2.0+ version.

I love looking at beautiful source-code output. However WordPress tends to spit code out in random chunks, often leaving spaces, line breaks, and tabs littered throughout the source output. This messes things up. Lists don’t look like lists and logically written code often appears scattered along the page carelessly. Often, this is the result of poorly written PHP, which can be manipulated to write beautifully aligned code that looks as good as it works.

For the first article in this series, we will bring order to the typical RDF chaos that WordPress spits out by default. To see an example of this, check out this source code, taken directly from the output of a default installation of WordPress. Notice how the awkward chunk of code leans, strangely enough, to the right. This type of RDF-code output seems to be the norm for WordPress users who have enabled that particular feature.

Okay, so it looks hideous, and we want to clean it up and make it shine. First thing to do is backup everything, even your database. Don’t trip though — this is a simple “cut-and-paste” procedure, but it is always a good idea to have a recent backup of your data just in case. Next, open the file wp-includes/comment-functions.php and find the function trackback_rdf, which is located about halfway down the page on line #525 (#509 for WP 2.0). Now, replace the following block of PHP code:

function trackback_rdf($timezone = 0) {
	global $id;
	if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
	echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
	    xmlns:dc="http://purl.org/dc/elements/1.1/"
	    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
		<rdf:Description rdf:about="';
	the_permalink();
	echo '"'."\n";
	echo '    dc:identifier="';
	the_permalink();
	echo '"'."\n";
	echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
	echo '    trackback:ping="'.trackback_url(0).'"'." />\n";
	echo '</rdf:RDF>';
	}
}

with our new and improved version1:

function trackback_rdf($timezone = 0) {
	global $id;
	if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
	echo '<rdf:RDF ';
	echo "\n";
	echo '   xmlns:dc="http://purl.org/dc/elements/1.1/" ';
	echo "\n";
	echo '   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
	echo "\n";
	echo '   xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';
	echo "\n";
	echo '<rdf:Description ';
	echo "\n";
	echo '   dc:creator="';
	the_author();
	echo '" '."\n";
	echo '   dc:date="';
	the_date_xml();
	echo ' @ ';
	the_time('g:i a');
	echo '" '."\n";
	echo '   dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'" '."\n";
	echo '   rdf:about="';
	the_permalink();
	echo '" '."\n";
	echo '   dc:identifier="';
	the_permalink();
	echo '" '."\n";
	echo '   trackback:ping="'.trackback_url(0);
	echo '" '."\n";
	echo '   dc:description="';
	the_excerpt_rss();
	echo '" />'."\n";
	echo '</rdf:RDF>';
	}
}

Finally, open your WordPress theme’s “index.php” file, find the loop, and add an echoed line break to the commented-out RDF function. Your code should now look like this:

<!--
<?php trackback_rdf(); ?>
<?php echo "\n"; ?>
-->

That’s it — save the two files, upload them, refresh your pages, and check the RDF output in the source code. If all goes well, your RDF code should now resemble this:

<!--
<rdf:RDF 
   xmlns:dc="http://purl.org/dc/elements/1.1/" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
   xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description 
   dc:creator="Perishable" 
   dc:date="2006-02-22 @ 11:19 am" 
   dc:title="WordPress RDF Source Makeover" 
   rdf:about="http://perishablepress.com/press/?p=49" 
   dc:identifier="http://perishablepress.com/press/?p=49" 
   trackback:ping="http://perishablepress.com/press/wp-trackback.php?p=49" 
   dc:description="Beautiful Source-Code Output, Part 1: Whip your WordPress RDF Code into Submission
I love looking at beautiful source-code output. [...continued &#187;]" />
</rdf:RDF>
-->

Now that’s much better!

Next time we will look at constructing righteous headings and pimping them for excellence on planet source-code output.

Update: To gain greater control over your WordPress RDF source-code output, replace the native function, the_excerpt_rss(); (located near the last line of the trackback_rdf() function), with the more flexible function, the_content_rss. This function provides five parameters as described in the WordPress Codex:

<?php the_content_rss('more_link_text', strip_teaser, 'more_file', cut, encode_html); ?>

More specifically, here is how we use the function to limit the number of words output in the dc:description attribute, thus optimizing bandwidth while preventing unruly code examples from disrupting document structure (as in the case of JavaScript comments):

the_content_rss('', TRUE, '', 7, 2);

Fin

References

Pathetic Phishing Attempt

Posted on February 12, 2006 in Nonsense by Jeff Starr

For a good laugh, consider the following email message:

Subject: Attention! Several VISA Credit Card bases have been LOST!

Good afternoon, unfortunately some processings have been cracked by hackers, so a new secure code to protect your data has been introduced by visa.

You should check your card balance and in case of suspicious transactions immediately contact your card issuing bank.

If all transactions are alright, it doesn’t mean the card is not lost and cannot be used. Probably, your card issuers have not updated information yet.

That is why we strongly recommend you to visit our web-site and update your profile, otherwise we cannot guarantee stolen money repayment.

Thank you for your attention.

Click here and update your profile.

Good times.

WordPress Notes Plus

Posted on February 12, 2006 in Websites, WordPress by Jeff Starr

Welcome to Perishable Press! This article covers many different aspects of WordPress functionality, including customizing quicktags, deleting the cache, numbering comments & posts, changing password text, and displaying archive menus. Note that this article was written for previous versions (i.e., less than 2.0) of WordPress. Discrepancies may exist between the code presented in this post and that of more recent versions of WordPress. Nonetheless, this information is presented for references purposes with the hope that it will prove useful for those working with everyone’s favorite blogging platform, WordPress!

Customize WordPress Quicktags

The more Quicktag:

The <!--more--> Quicktag breaks a post into “teaser” and content sections. Type a few paragraphs, insert this tag, then compose the rest of your post. On your blog’s home page you’ll see only those first paragraphs with a “(more…)” hyperlink, which when followed displays the rest of the post’s content.1

Customize the more Quicktag:

To customize the “(more…)” hyperlink, open the file “wp-includes/template-functions-post.php” and locate the following lines (around lines #54 & #62, respectively):

function the_content($more_link_text = '(more...)', $str...
function get_the_content($more_link_text = '(more...)', $str...

For each line, carefully replace (more...) with whatever text you wish. Possibilities include Continued >> and [ Read on... ].

Modify the Target of the more Quicktag:

To modify the target of the “(more…)” hyperlink, replace the following statement (located within “wp-includes/template-functions-post.php” around line #92):

$output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";

with:

$output .= ' <a href="'. get_permalink() . "\">$more_link_text</a>";

The nextpage Quicktag:

The <!--nextpage--> Quicktag is similar to the more tag, except it can be used any number of times in a post, and each insert will “break” and paginate the post at that location. Hyperlinks to the paginated sections of the post are then generated in combination with the wp_link_pages() or link_pages() template tag.2

Customize the_excerpt Function

Open the file “wp-includes/functions-formatting.php” and find the following line of code (located around line #732):

array_push($words, '[...]');

To customize the continuation notation for excerpts, simply replace [...] with the text of your choice. Something like “[...continued &raquo;]” or “[ click post title to read more ]” works just swell.

To change the default number of words included in excerpts, edit the 55 in the following line of code (located around line #728) to reflect the desired number of excerpt words:

$excerpt_length = 55;

Fix the WordPress "Remember Me" Option

If the WordPress admin seems to “forget” you even after following all of the proper protocols, try changing the actual link that takes you to your WP admin-login page. Change the link from /wp-login.php (the file) to /wp-admin/ (the directory).

Cache Notes

It is totally safe to delete everything in the /wp-content/cache/ folder!

Custom Number of Posts

Sometimes it is nice to customize the number of posts displayed for different loops. For example, if you have different themes, it is possible for one theme to show five posts while another theme only shows one post. To pull it off, simply place the following line of PHP before the loop:

<?php query_posts('showposts=n'); ?>

Where "n" represents the number of posts that the loop will display 3. Nice ;) Update: This method needs some work — seemed okay at first, but then links to posts always go to the first blog page..

Tweaking Comment Numbers

Instruct WordPress to begin each post’s comment numbers with the number "1" (or any number), and then proceed numerically thenceforth by adding this line at the top of comments.php..

<?php $commentcount=1; // number of first comment for each post ?>

..and then placing this line at the location where you would like the comment numbers to appear:

<?php echo $commentcount++; ?>

Another method for accomplishing the same thing involves replacing this code (located in comments.php)..

<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : ?>

..with this..

<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : $comment_count++;?>

..and then placing this line at the location where you would like the comment numbers to appear:

<?php echo $commentcount++; ?>

Customize Default Password Text

To change the default WordPress password text, open the file "wp-includes/comment-functions.php", and scroll to around line #309. Look for the password text and change it to whatever you prefer. Note: this default password text is different than the password text specified in the comments.php file.

Dropdown Archive Menus

To create dropdown archive menus (using get_archives4), simply emulate one of the following chunks of code and tweak to suit:


<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('daily','33','option','','','FALSE'); ?>
</select>

<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('postbypost','33','option','','','FALSE'); ?>
</select>

<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Monthly Archives</option>
<?php get_archives('monthly','12','option','','','TRUE'); ?>
</select>

<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('daily','7','option','','','FALSE'); ?>
<option value="">Monthly Archives</option>
<?php get_archives('monthly','7','option','','','TRUE'); ?>
<option value="">Yearly Archives</option>
<?php get_archives('weekly','7','option','','','TRUE'); ?>
</select>

References

Scenes from Deep Space

Posted on February 6, 2006 in Nonsense by Jeff Starr

The Millennium Falcon speeds through deep space, closely followed by a firing Imperial Star Destroyer. A large asteroid about the same size as the Falcon tumbles rapidly toward the starship. The tiny Falcon banks to avoid the giant asteroid as smaller rocks pelt its surface. Then the small craft roars under the asteroid which explodes harmlessly on the hull of the vast Star Destroyer.

Ready, are you? What know you of ready? For eight hundred years have I trained Jedi. My own counsel will I keep on who is to be trained! A Jedi must have the deepest commitment, the most serious mind. This one a long time have I watched. Never his mind on where he was. Hmm? What he was doing. Hmph. Adventure. Heh! Excitement. Heh! A Jedi craves not these things. You are reckless!

Clutching desperately at his throat, Captain Needa slumps down, then falls over on his back, at the feet of Darth Vader. Two stormtroopers pick up the lifeless body and carry it quickly away as Admiral Piett and two of his captains hurry up to the Dark Lord.

Website in Development

Posted on February 1, 2006 in Business, Nothing by m0n

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam nunc vitae purus. Aenean viverra malesuada libero. Fusce ac quam. Donec neque. Nunc venenatis enim nec quam. Cras faucibus, justo vel accumsan aliquam, tellus dui fringilla quam, in condimentum augue lorem non tellus. Pellentesque id arcu non sem placerat iaculis. Curabitur posuere, pede vitae lacinia accumsan, enim nibh elementum orci, ut volutpat eros sapien nec sapien. Suspendisse neque arcu, ultrices commodo, pellentesque sit amet, ultricies ut, ipsum. Mauris et eros eget erat dapibus mollis. Mauris laoreet posuere odio. Nam ipsum ligula, ullamcorper eu, fringilla at, lacinia ut, augue. Nullam nunc.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam nunc vitae purus. Aenean viverra malesuada libero. Fusce ac quam. Donec neque. Nunc venenatis enim nec quam. Cras faucibus, justo vel accumsan aliquam, tellus dui fringilla quam, in condimentum augue lorem non tellus. Pellentesque id arcu non sem placerat iaculis. Curabitur posuere, pede vitae lacinia accumsan, enim nibh elementum orci, ut volutpat eros sapien nec sapien. Suspendisse neque arcu, ultrices commodo, pellentesque sit amet, ultricies ut, ipsum. Mauris et eros eget erat dapibus mollis. Mauris laoreet posuere odio. Nam ipsum ligula, ullamcorper eu, fringilla at, lacinia ut, augue. Nullam nunc.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam nunc vitae purus. Aenean viverra malesuada libero. Fusce ac quam. Donec neque. Nunc venenatis enim nec quam. Cras faucibus, justo vel accumsan aliquam, tellus dui fringilla quam, in condimentum augue lorem non tellus. Pellentesque id arcu non sem placerat iaculis. Curabitur posuere, pede vitae lacinia accumsan, enim nibh elementum orci, ut volutpat eros sapien nec sapien. Suspendisse neque arcu, ultrices commodo, pellentesque sit amet, ultricies ut, ipsum. Mauris et eros eget erat dapibus mollis. Mauris laoreet posuere odio. Nam ipsum ligula, ullamcorper eu, fringilla at, lacinia ut, augue. Nullam nunc.