Up Down

This might not seem like a big deal, but I finally got the image headers working properly.

Basically, I need an image there to be of the character/creator/series/edition/etc IF there is an image file in the specified folder.

If not, I wanted it to “fail gracefully” by using some kind of filler image. I couldn’t figure out a way to do it that worked for every browser until today.

With a nudge in the right direction from the wordpress subreddit, I finally got this code (or versions of it for tags and categories) working:

<?php
if ( is_tax(‘marvel-character’) ) {
$image_url=”http://www.tradereadingorder.com/default-images/marvel.jpg”;
$term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) );
$image_path =”ABSOLUTE/SERVER/PATH” .$term->slug.”.jpg”;
if ( file_exists($image_path) ) {
$image_url = “http://www.tradereadingorder.com/marvel-character-image/” .$term->slug.”.jpg”;
}
echo ‘<img src=”‘ . $image_url. ‘”>’;
}
?>

Sweet, huh? Took a few hours of tweaking to finally get it right, with some misplaced punctuation and figuring out the root path thing (originally I was just trying the regular path, but that doesn’t work for file_exists.) Also, I was first told about the function as “file_exist” – missing that all important “s” at the end!

While getting it implemented for each taxonomy and testing the results, I found that the novel-series one isn’t working for some reason. I’ve sought after help to figure this out. The code is exactly the same for this taxonomy as every other one, so I don’t know why it isn’t working. Anyway, we’ll figure it out sooner or later – or I’ll just make a new taxonomy that does work. WordPress is awful quirky sometimes.

Edit: There’s still something wrong with the novel-series category slug, but again the wordpress subreddit to the rescue. We’re setting a custom rewrite for that one taxonomy, so it displays as a somewhat cumbersome novel–series, but at least it works. I have no idea why the original doesn’t, but maybe it could be fixed in the future. Let me know if you see anything else that’s broken.

Here are the new header images:

Want to stay up to date? Click here to subscribe to updates by RSS!
You can also sign up to get updates by Email!
« | »

4 Comments Post New »

  1. world manufacturers wrote on at September 23, 2011 2:56 pm:

    Hi, this is a comment.
    To delete a comment, just log in and view the post’s comments. There you will have the option to edit or delete them.

    [Reply]

  2. music marketing tv series wrote on at July 4, 2014 3:57 am:

    Its like you learn my mind! You seem to grasp a lot
    about this, such as you wrote the guide in it or something.
    I think that you can do with a few percent to pressure the message home
    a bit, but other than that, that is wonderful blog.
    A fantastic read. I will definitely be back.

    [Reply]

  3. Angie wrote on at December 3, 2014 10:07 am:

    This is a comment to the webmaster. Your WordPress Custom Taxonomy Image Headers, File_Exists Implemented! | Trade Reading Order website is missing out on at least 300 visitors per day. I have found a company which offers to dramatically increase your visitors to your site: http://tho.lu/42v They offer 500 free visitors during their free trial period and I managed to get over 15,000 visitors per month using their services, you could also get lot more targeted visitors than you have now. Hope this helps :) Take care.

    [Reply]

  4. Jacqueline wrote on at June 18, 2015 12:47 pm:

    Hi my name is Jacqueline and I just wanted to drop you a quick note here instead of calling you. I came to your WordPress Custom Taxonomy Image Headers, File_Exists Implemented! | Trade Reading Order page and noticed you could have a lot more visitors. I have found that the key to running a popular website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get targeted visitors from and they let you try their service for free for 7 days. I managed to get over 300 targeted visitors to day to my site. Check it out here: http://txsc.us/t4ut

    [Reply]

Trackbacks and Related Posts

Content from other blogs and on this site that links back to this post.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Registered users may edit their comments past the 5 minute limit. [Register] [Login] [Logout]
HTML is allowed, but posts containing more than two links or sketchy code will be held for moderation.

« | »