6 useful Thematic snippets

I thought I’d write some­thing web­design related to fill the almost empty Web­design cat­egory on this blog, and since I use the Them­atic Theme Frame­work and find it is the best thing that can hap­pen to a Word­Press blog I decided to share a couple of modi­fic­a­tions for it. (These snip­pets go into the functions.php file of your child theme).

Integ­rat­ing cus­tom taxonomies

OK, so with the release of Word­Press 2.8 cus­tom tax­onom­ies became really very easy. They’re used on all kinds of blogs, from mark­ing post series on web­dev tutorial blogs to lib­rary man­age­ment on stream­ing portals. What you usu­ally see at the bot­tom meta of our posts as ‘in con­nec­tion with’ is the fol­low­ing modi­fic­a­tion in con­nec­tion with the Anime Drop­down Wid­get I developed. (The wid­get cre­ates a cus­tom tax­onomy called ‘anime’ and lets you organ­ize related posts bet­ter way).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 = ' <span class="meta-sep meta-sep-tag-links">|</span>';
    endif;
    $taxonomytags = get_the_term_list($post->ID, $taxonomy_slug, $context, ', ', $sep);

    return $postcat.$taxonomytags;
}

add_filter ('thematic_postfooter_postcategory', 'addaftercat');

All you need to cus­tom­ize here is $taxonomy_slug and $context.

Insert­ing things right after posts

Although it’s been annoy­ing me lately, the fam­ous blog­ger Danny Choo has a huge self-promotion text after each post, encour­aging reader to sub­scribe to his RSS feed and fol­low him on what-not. As if some­body wouldn’t have done it already… Any­way, it’s the easi­est of things to do:

1
2
3
4
5
6
7
8
9
10
function addfeedpromotion($content) {
    $insert = "";
    if(is_singular()):
        $insert = 'If you liked reading this post, <a href="' . get_bloginfo('rss2_url') . '">subscribe to our RSS feed</a> to get more of it right to your feedreader!';
    endif;

    return $content;
}

add_filter('the_content', 'wt_addids');

This inserts the RSS link after the text of each post on single pages.

Mak­ing post images linkable-to

I have never seen this on Word­Press blogs, but the above-mentioned Danny Choo’s images all have an id attrib­ute which makes them linkable-to via #imageid. The fol­low­ing code is inven­ted by me though, I thought of releas­ing a plu­gin but didn’t see that some­body needed it at all. Mostly because the major­ity of people I know are not pho­tob­log­gers or art-bloggers. Any­way, this code wrap all images in a post in div-tags with the ID of the image as in the Word­Press database.

1
2
3
4
5
6
7
8
9
10
function addimageids($content) {
    if(is_singular()):
        $content = preg_replace('/(?:|]*>?)]*class="([^"]*)wp-image-(\d+)[^>]*\/>(?:|>\/a[^>]*>?)/', '<div id="image-${2}" class="${1}">${0}</div>
'
, $content);
    endif;

    return $content;
}

add_filter('the_content', 'addimageids', 9999);

As you see it also cop­ies each image’s class so there shouldn’t be any align­ment prob­lems. On this blog, the trans­par­ent link on the images is added via JavaS­cript, although you can hard­code it or let it be at all.

Remov­ing Thematic-specific scripts

If you’re not going to use the page menu effects, you prob­ably would want to remove the unne­ces­sary scripts from header. Or altern­at­ively, you could replace them and/or other scripts with a com­pressed ver­sion with help of Minify. Either way, you’ll need this code snippet:

1
2
3
4
5
6
7
8
9
function modifyscripts() {
    $content = "\n";
    $content .= ''; //Put own scripts here if you want
    $content .= "\n";

    return $content;
}

add_filter('thematic_head_scripts','modifyscripts');

Remove default stylesheet linking

I wouldn’t know why you would want to remove the stylesheets, but this snip­pet is actu­ally exactly the same as the above one, and is very good for optim­iz­ing page load times. In this example we will replace the default link­ing to the optim­ized ver­sion of it (optim­ized with the pre­vi­ously linked Minify, assum­ing you have it installed in your blog’s root folder):

1
2
3
4
5
6
7
function optimizestylesheet($content) {
    $content = '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('url') . '/min/b=wp-content&amp;f=themes/thematic/library/styles/reset.css,themes/thematic/library/styles/typography.css,themes/thematic/library/layouts/2c-r-fixed.css" />';

    return $content;
}

add_filter('thematic_create_stylesheet', 'optimizestylesheet');

Adding meta to <head>

Like, if you want to add Google veri­fic­a­tion code or some­thing sim­ilar (or gen­er­ally any stuff one can put into the head of a page), use this snippet:

1
2
3
4
5
6
7
function metathings() {
    ?>
    <meta name="verify-v1" content="YOUR_GOOGLE_CODE_HERE" />
    <?php
}

add_filter('wp_head', 'metathings');

Ini­tially I planned to intro­duce 10 of them snip­pets, but at last there weren’t too many I didn’t already see else­where to begin with. More than that, you see those 10÷50÷100 so often that I thought it’d be nice to have num­ber without the null at least once. ^^

All of the above code ‘excerpts’ (to not repeat the word ‘snip­pet’ again, as that would be a styl­istic fail­ure for me) (oh sh-) are used on a², just so you know. With that, I con­clude my first real (if you approve of its ‘real­ness’) web­design post on Anime².

Fur­ther reading

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
This entry was posted in Webdesign and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

12 Comments

  1. Ryan A 51
    Posted November 2, 2009 at 20:40 | Permalink

    Macar­oni! That tax­onomy thing looks pretty awe­some. Very spiff stuff.

  2. Posted November 2, 2009 at 21:01 | Permalink

    Hmm, inter­est­ing! Kabitzin also had some blogging-tips back in the day =D This could be use­ful later on =3

    (/advertisement)

    • Posted November 2, 2009 at 21:11 | Permalink

      haha, my name still col­lides with the com­ment box! I love it though! >=D

    • Gargron 482
      Posted November 2, 2009 at 21:15 | Permalink

      Holy Sage Wolf Horo, so shame­less! I wish I c-could be like y-you, too, senpai~!!

      • Posted November 2, 2009 at 21:46 | Permalink

        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 inter­ested in building/designing blogs. Have you ever con­sidered 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

        • Gargron 482
          Posted November 2, 2009 at 22:13 | Permalink

          you’re still very young

          Heya! I’m just a little bit younger than you, sen­pai! And I have facial hair, hurr durr~

          But yeah, when some­body asks me who I want to be I reply ‘either anim­ator or web­designer.’ But you know, a short time ago I sud­denly real­ised that my dream is to open a café, a real european café with lots of books and tasty sweets and um, maids.

  3. Posted November 2, 2009 at 21:17 | Permalink

    Cool snip­pets! A couple of them I didn’t know about!

  4. Posted December 5, 2009 at 16:57 | Permalink

    Thanks Eugen, that’s what I call a nice post! You should, in my opin­ion, cre­ate a second blog for Word­Press and Web Devel­op­ment.
    Jean-Baptiste Jung´s last blog post: Should you write “List posts” on your blog?

    • Gargron 482
      Posted December 5, 2009 at 17:09 | Permalink

      Thanks for the com­pli­ment! I will def­in­itely con­sider it. Although I think this blog could make it to appeal to both anib­lo­go­sphere and webdesign-o-sphere and make people of both inter­ested in each other. What do you think?

  5. Posted December 5, 2009 at 18:59 | Permalink

    Hey Gar­g­ron. I also have a list of use­ful them­atic fil­ters. I have you linked at the bot­tom of my list. Cheers!
    Devin Price´s last blog post: Dynamic CSS Stylesheets and Them­atic

    • Eugen R. 482
      Posted December 5, 2009 at 21:31 | Permalink

      I know, I’ve seen it. But well, I also know what the pur­pose of this com­ment is. I guess every com­ment is a com­ment. You’re welcome.

2 Trackbacks

  1. By Vote on this article at blogengage.com on November 28, 2009 at 20:43

    6 use­ful Them­atic Snippets…

    A list (yes, a list post) with 6 ori­ginal and use­ful code snip­pets for the Them­atic Theme Frame­work. They may be not everybody’s needed func­tion­al­ity, but they are def­in­itely good func­tion­al­ity and as proof, my blog uses them all.…

  2. By Year in Overview: 2009 on January 5, 2010 at 18:44

    […] […]

Post a Comment

Do not spam. Do not name yourself after website names. To have an avatar, register at gravatar. Note: your e-mail will never be published or used, it is needed only to ensure you're not a spambot.

Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting