I thought I’d write something webdesign related to fill the almost empty Webdesign category on this blog, and since I use the Thematic Theme Framework and find it is the best thing that can happen to a WordPress blog I decided to share a couple of modifications for it. (These snippets go into the functions.php file of your child theme).
Integrating custom taxonomies
OK, so with the release of WordPress 2.8 custom taxonomies became really very easy. They’re used on all kinds of blogs, from marking post series on webdev tutorial blogs to library management on streaming portals. What you usually see at the bottom meta of our posts as ‘in connection with’ is the following modification in connection with the Anime Dropdown Widget I developed. (The widget creates a custom taxonomy called ‘anime’ and lets you organize related posts better way).
[cc lang=“php”]
function addaftercat($postcat) {
global $post;
$sep = “”;
$taxonomy_slug = “anime”; //The unique slug of the taxonomy tags to show
$context = ” in connection with “; //Any text, like ’ filed under ’ or whatever
if(!is_single()):
$sep = ’ ’;
endif;
$taxonomytags = get_the_term_list($post->ID, $taxonomy_slug, $context, ‘, ‘, $sep);
return $postcat.$taxonomytags;
}
add_filter (‘thematic_postfooter_postcategory’, ‘addaftercat’);
[/cc]
All you need to customize here is $taxonomy_slug and $context.
Inserting things right after posts
Although it’s been annoying me lately, the famous blogger Danny Choo has a huge self-promotion text after each post, encouraging reader to subscribe to his RSS feed and follow him on what-not. As if somebody wouldn’t have done it already… Anyway, it’s the easiest of things to do:
[cc lang=“php”]
function addfeedpromotion($content) {
$insert = “”;
if(is_singular()):
$insert = ‘If you liked reading this post, subscribe to our RSS feed to get more of it right to your feedreader!’;
endif;
return $content;
}
add_filter(‘the_content’, ‘wt_addids’);
[/cc]
This inserts the RSS link after the text of each post on single pages.
Making post images linkable-to
I have never seen this on WordPress blogs, but the above-mentioned Danny Choo’s images all have an id attribute which makes them linkable-to via #imageid. The following code is invented by me though, I thought of releasing a plugin but didn’t see that somebody needed it at all. Mostly because the majority of people I know are not photobloggers or art-bloggers. Anyway, this code wrap all images in a post in div-tags with the ID of the image as in the WordPress database.
[cc lang=“php”]
function addimageids($content) {
if(is_singular()):
$content = preg_replace(‘/(?:|]*>?)]*class=”([^”]*)wp-image-(\d+)[^>]*\/>(?:|>\/a[^>]*>?)/’, ‘
‘, $content);
endif;
return $content;
}
add_filter(‘the_content’, ‘addimageids’, 9999);
[/cc]
As you see it also copies each image’s class so there shouldn’t be any alignment problems. On this blog, the transparent link on the images is added via JavaScript, although you can hardcode it or let it be at all.
Removing Thematic-specific scripts
If you’re not going to use the page menu effects, you probably would want to remove the unnecessary scripts from header. Or alternatively, you could replace them and/or other scripts with a compressed version with help of Minify. Either way, you’ll need this code snippet:
[cc lang=“php”]
function modifyscripts() {
$content = “\n”;
$content .= ”; //Put own scripts here if you want
$content .= “\n”;
return $content;
}
add_filter(‘thematic_head_scripts’,‘modifyscripts’);
[/cc]
Remove default stylesheet linking
I wouldn’t know why you would want to remove the stylesheets, but this snippet is actually exactly the same as the above one, and is very good for optimizing page load times. In this example we will replace the default linking to the optimized version of it (optimized with the previously linked Minify, assuming you have it installed in your blog’s root folder):
[cc lang=“php”]
function optimizestylesheet($content) {
$content = ‘
’;
return $content;
}
add_filter(‘thematic_create_stylesheet’, ‘optimizestylesheet’);
[/cc]
Adding meta to <head>
Like, if you want to add Google verification code or something similar (or generally any stuff one can put into the head of a page), use this snippet:
[cc lang=“php”]
function metathings() {
?>
<?php
}
add_filter(‘wp_head’, ‘metathings’);
[/cc]
Initially I planned to introduce 10 of them snippets, but at last there weren’t too many I didn’t already see elsewhere to begin with. More than that, you see those 10÷50÷100 so often that I thought it’d be nice to have number without the null at least once. ^^
All of the above code ‘excerpts’ (to not repeat the word ‘snippet’ again, as that would be a stylistic failure for me) (oh sh-) are used on a², just so you know. With that, I conclude my first real (if you approve of its ‘realness’) webdesign post on Anime².
13 Comments
Macaroni! That taxonomy thing looks pretty awesome. Very spiff stuff.
Hmm, interesting! Kabitzin also had some blogging-tips back in the day =D This could be useful later on =3
(/advertisement)
haha, my name still collides with the comment box! I love it though! >=D
Holy Sage Wolf Horo, so shameless! I wish I c-could be like y-you, too, senpai~!!
Wanna be just like me? SIMPLE! JUST 5 EASY PAYMENTS OF LEAVING COMMENTS ON SEAS SLUGS AND-*smacks himself*
so yea, you seem to be quite interested in building/designing blogs. Have you ever considered that as a career path? I know you’re still very young, but you seem to enjoy it a lot. Just wanted to put that out =3
Heya! I’m just a little bit younger than you, senpai! And I have facial hair, hurr durr~
But yeah, when somebody asks me who I want to be I reply ‘either animator or webdesigner.’ But you know, a short time ago I suddenly realised that my dream is to open a café, a real european café with lots of books and tasty sweets and um, maids.
Cool snippets! A couple of them I didn’t know about!
Thank you, I feel really honoured. ^^
Thanks Eugen, that’s what I call a nice post! You should, in my opinion, create a second blog for WordPress and Web Development.
Jean-Baptiste Jung´s last blog post: Should you write “List posts” on your blog?
Thanks for the compliment! I will definitely consider it. Although I think this blog could make it to appeal to both aniblogosphere and webdesign-o-sphere and make people of both interested in each other. What do you think?
Hey Gargron. I also have a list of useful thematic filters. I have you linked at the bottom of my list. Cheers!
Devin Price´s last blog post: Dynamic CSS Stylesheets and Thematic
I know, I’ve seen it. But well, I also know what the purpose of this comment is. I guess every comment is a comment. You’re welcome.
Hello my good friend you definitely have a great blog and site on here about certain health concerning issues. Actually I was just looking this kind of information to put on my blog that might be interesting to people because I too also am in First Aid industry myself and give Health & Safetly and First Aid+ Training to small companies and individuals. Thanks for the good articles on this post and hope to see more soon as is being helpful to people and myself. Visit my site to see more info on me and my website at http://www.firstaidatworkinwestsussex.com/
Even Richards
2 Trackbacks
6 useful Thematic Snippets…
A list (yes, a list post) with 6 original and useful code snippets for the Thematic Theme Framework. They may be not everybody’s needed functionality, but they are definitely good functionality and as proof, my blog uses them all.…
[…] […]