Posts Tagged ‘wordpress’

Robotic Relative

Wednesday, January 13th, 2010

Just finished RoboticRelative.com (many of you have probably already seen the early updates, so sorry if your already in the loop on this) and it’s running beautifully. The site is verbatim from Jess’ Illustrator file and instruction, but the magic on my part includes a few enhancements from the latest in WordPress goodies. My favorite being the new ‘the_post_thumbnail()’ function which allows for a plugin-less and dynamic output of thumbnails (though documentation and the built-in media editor leave a little to be desired)..

Check it out at roboticrelative.com , you’ll come away inspired to get in touch with somebody and be all tingly on your insides… Jess is truly talented!

roboticrelative.com

Wordpress Installation and Theme Development, Peter Demaria © 2009

Tags: , , ,
Posted in web | No Comments »

The Bushwhacker…

Wednesday, January 13th, 2010

This site is my father-in-laws, and isn’t a site I technically get paid to design or update, so the time I’m able to spend on it is limited. Its definitely not in its final iteration , there are some typography issues, and it doesn’t always play the nicest with IE6 (yet), but overall I’m really happy with the look and feel of the site, as is the author…

The numechron clock  (the authors own) is also a fine example of some simple flash enhancement, a practical addition to the sidebar that enhances the overall atmosphere of modern antiquity-ishness.

Note: The opinions and viewpoints of “the Bushwhacker” in NO way whatsoever reflect my own views. That said, he does have some strong (and conservative) religious and political views and ideas, and if this is your cup of tea you might enjoy it…. I know this for sure, he’d love to debate them with you!

thebushwacker.com

Blog Design & WordPress Theme, Peter Demaria © 2009

Tags: , , , ,
Posted in web | No Comments »

Straight up Functional?

Monday, October 19th, 2009

Had a minor conundrum the other day involving some pretty standard WordPress type stuff.. as these things usually sometimes go, it was about 1:30 am before I actually had a working solution. Note, solutions below are not for beginners, you WILL break your theme if you don’t implement the code properly.

The problem seemed like a no-brainer at first, if you want to display a preview of a post WordPress offers two options, the_excerpt() and the_content(). If you are using the_content() you have to manually insert a ‘read more’ tag wherever you need it to appear when readers are viewing the appended version of your post. I opted for the_excerpt(), which nicely and dynamically generates a brief version of an article (or an optional, manually written excerpt), along with whatever other information you decide to include along with it in the loop.

BUT, out of the box the_excerpt() adds a nifty little blob to the end of each excerpt unless you fill in your excerpt manually, looks like this [...]  Not pretty… of course there are plugins to spice up your excerpts and all that, but whenever possible I like to do a little future-proofing by writing actual code that can be baked into a theme. A little logic or some-such thing. I liked the solution I found at WP Engineer (which has conveniently disappeared, replaced by information for not-yet-released WordPress 2.9), which when added to your functions.php file, supplants WordPress’ own the_excerpt() functionality. Replace ‘better_trim_excerpt’ with your own name if your feeling feisty…

<?php
function better_trim_excerpt($text) {
	global $post;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]>', ']]&gt;', $text);
		$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
		$text = strip_tags($text);
		$excerpt_length = 45;
		$words = explode(' ', $text, $excerpt_length + 1);
		if (count($words)> $excerpt_length) {
			array_pop($words);
			array_push($words, '...');//'...' is what replaces the unsightly blob..
			$text = implode(' ', $words);
		}
	}
	return $text;
}
?>

Just one problem, WordPress’s wondrous auto-generated captioning was being stripped from the resulting html, but not the content of the caption (leaving hideous random text willy-nilly). Add this bit of code to our previous solution, and problem solved..

<pre>add_filter( 'img_caption_shortcode', create_function('$a, $b, $c', 'return $c;'), 10, 3 );</pre>

which gives us the following;


<?php
function better_trim_excerpt($text) {
 global $post;
 if ( '' == $text ) {
 add_filter( 'img_caption_shortcode', create_function('$a, $b, $c', 'return $c;'), 10, 3 );
 $text = get_the_content('');
 $text = apply_filters('the_content', $text);
 $text = str_replace(']]>', ']]&gt;', $text);
 $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
 $text = strip_tags($text);
 $excerpt_length = 45;
 $words = explode(' ', $text, $excerpt_length + 1);
 if (count($words)> $excerpt_length) {
 array_pop($words);
 array_push($words, '...');//'...' is what replaces the unsightly blob..
 $text = implode(' ', $words);
 }
 }
 return $text;
}
?>
<?php
remove_filter('get_the_excerpt', 'wp_trim_excerpt');//removes wp hook for excerpt function
add_filter('get_the_excerpt', 'better_trim_excerpt');//points wordpress to yours, name this whatever you want!
?>

Having gone through all of this, today I discovered that the_excerpt() is bound for a makeover, and with the release of 2.9 two lines of code may accomplish what took me twenty-three or so. Though I’m not positive it will solve my caption problems…

Tags: , , ,
Posted in Updates | No Comments »