• Resolved bloggingcss

    (@bloggingcss)


    Hi all,

    I’ve got a problem over at my blog, Blogging CSS. You can see I use a little square image on the top-right corner of the post image to signal the category it belongs to. The whole image, title and category icon are displayed with custom fields. Here is the code:

    <div id="post-preview">
       <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>" class="postTitle"><?php the_title(); ?></a></h1>
       <?php $image = get_post_meta($post->ID, "post_image", true); ?>
       <?php $cat = get_post_meta($post->ID, "cat_icon", true); ?>
       <img src="wp-content/themes/default/images/<?php echo $cat; ?>.png" alt="<?php echo $cat; ?>" class="cat-icon" />
       <a href="<?php the_permalink(); ?>" class="screenshot"><img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" class="fullColumn" /></a>
    </div>

    Everything works in the home page, but if you click on any of the previous pages, the category icon is replaced by it’s alt attribute, althought I’ve pasted the same exact code in the archives page template too.

    Does anybody have an idea why this could be happening?

Viewing 2 replies - 1 through 2 (of 2 total)
  • it’s because you’re using a relative url for the image. When you go to another page, the url is then relative to that page – you need to add the wordpress url in:

    <img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/default/images/<?php echo $cat; ?>.png" alt="<?php echo $cat; ?>" class="cat-icon" />

    Thread Starter bloggingcss

    (@bloggingcss)

    Aww, right. Thanks 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Layout difference in previous pages’ is closed to new replies.