ThemeShaper Forums » Thematic

[closed]

Custom Fields - Display thumbnail to the left of post

(7 posts)
  • Started 11 years ago by katiek648
  • Latest reply from liz_eff
  • This topic is not resolved
  1. katiek648
    Member

    Can someone help me? I'm trying to set a thumbnail to the left of a post summary on a category page, but it doesn't seem to recognize my custom field. I've set the custom field to 'post-img' on the post page. Then I've added this code to the content-extensions.php page within the Categy Loop before the <div id="post-

    <?php $postimageurl = get_post_meta($post->ID, 'post-img', true);
    if ($postimageurl) {
    ?>
          <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" /></a>
    <?php } else { ?>
          <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="/wp-content/themes/lonjevitea/images/default.gif" alt="Screenshot" width="200" height="150" /></a>
    <?php } ?>

    For some reason the custom field is not working. It shows the default image okay, but does not recognize that I have a post-img value in there. Can someone help? Or show me better way to do this?

    Thanks!

    Posted 11 years ago #
  2. mrsteveman1
    Member

    I'm also interested in this, if anyone finds out a good way to do this before I figure it out please post :)

    Posted 11 years ago #
  3. First off you really would be better off in the long run if you developed a child theme. Modding the thematic's files is gonna cause a headache down the road should the thematic theme get updated later and you want to upgrade.

    The custom field is not displaying in your example because of the reference to $post->ID Since the loop is being called from a function, if you want to pull the ID out of the global $post array the global needs to be declared in the function.

    In a child theme you would put this in your functions.php otherwise just declare global $post; at the beginning of the code you added.

    function remove_category_loop(){
        remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    add_action('init','remove_category_loop');
    
    function child_category_loop() {
    
        global $post;  
    
        while (have_posts()) : the_post();
    
          $postimageurl = get_post_meta($post->ID , 'post-img', true);
          if ($postimageurl) {?>
            <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" /></a>
            <?php } else { ?>
            <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="/wp-content/themes/lonjevitea/images/default.gif" alt="Screenshot" width="200" height="150" /></a>
            <?php } ?>
    
            <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
               <?php thematic_postheader(); ?>
               <div class="entry-content">
                 <?php thematic_content(); ?>
               </div>
               <?php thematic_postfooter(); ?>
            </div><!-- .post -->
    
         <?php endwhile;
    }
    add_action('thematic_categoryloop', 'child_category_loop');
    Posted 11 years ago #
  4. I like where you're going with this, em hr. I also want a thumbnail to show beside the entry-title and entry-meta fields. I'd like to use to your code in the functions.php page of my child theme. However, I'd like to omit the step of adding a plug-in.

    Instead, I am simply adding an image to the excerpt section when I add/edit the post. I tried to replace 'post-img' with 'post-excerpt' in the line:

    $postimageurl = get_post_meta($post->ID , 'post-img', true);

    but it didn't quite work. a little help?

    thanks!

    liz

    Posted 10 years ago #
  5. ok, I corrected a mistake, changing "post-excerpt" to "post_excerpt", but let me clarify what i'm looking for:

    i'd like to show the image on the left and the title and date NEXT TO the image on the right. Because I'm entering the image into the "excerpt" field, I am no longer including the text excerpt.

    I think I can just do this with CSS, but I want to be sure that I don't affect the CSS on the actual post (for example, if i edit .entry-title{} in child_theme.css, i want to be sure that it doesn't affect the entry title of the actual post, but only on the category archive page.

    any ideas would be great...

    Posted 10 years ago #
  6. Hi liz,

    Use the body class for specificity.

    .category .entry-title{}

    -Gene

    Posted 10 years ago #
  7. ahh! i settled for category icons on archive pages and posts, which was a cinch with the following code:

    .entry-content, .entry-title {
    padding-left: 10px;
    }

    .category-x {
    background: url(images/logo.png) no-repeat top left;
    margin-left: 5px;
    }

    thanks for your help, em hr. i always benefit from your comments.

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.