ThemeShaper Forums » Thematic

[closed]

Adding post-thumbnails to monthly archives

(9 posts)
  • Started 9 years ago by rkread
  • Latest reply from flick
  • This topic is resolved
  1. rkread
    Member

    I've created a Thematic child theme. I want to add the post-thumbnail feature to the monthly archives pages. Currently, I have the following code in my functions.php file which displays the post-thumbnails on the Category pages:

    // Enable Post Thumbnail Images
    
    //* First we will add the thumbnail feature *//
    add_theme_support('post-thumbnails');
    	set_post_thumbnail_size(128, 128, true );
    
     //* Thumbnails on category pages *//
    function my_post_title($title) {
    	if (is_category()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    	} else {
    		return $title;
    	}
    }
    add_filter('thematic_postheader_posttitle', 'my_post_title');

    I tried repeating the same code, but substituting if (is_archives()) for if (is_category()), but that didn't work.

    Research shows how to put code into template pages but since this is a child theme I'm wondering if I do it differently. thanks everyone.

    Posted 9 years ago #
  2. Hi rkread,

    That's becauseis_archives() does not exists as a conditional tag...

    Try : is_archive()

    -Gene

    Posted 9 years ago #
  3. rkread
    Member

    Thanks Gene, actually I did try that, but it didn't work for me. No error message, just a blank page.
    I added the following code:

    //* Thumbnails on archives pages *//
    function my_post_title($title) {
    	if (is_archive()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    	} else {
    		return $title;
    	}
    }
    add_filter('thematic_postheader_posttitle', 'my_post_title');

    Any other thoughts or suggestions? Thanks so much for your help.

    Posted 9 years ago #
  4. rkread
    Member

    FYI, solved this issue with more research on this board. As a newbie I didn't know exactly how to "cascade" PHP code as referenced here, but a little trial and error worked it out.

    This code, placed in the functions.php file gives me post-thumbnails on category, monthly archive and search result pages in my Thematic child theme.

    //* Thumbnails on category, archive and search pages *//
    function my_post_title($title) {
    	if (is_category()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    	} elseif (is_archive()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    	} elseif (is_search()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    	}
    	else {
    		return $title;
    	}
    
    }
    
    add_filter('thematic_postheader_posttitle', 'my_post_title');
    Posted 9 years ago #
  5. @rkread: I think it might be possible to achieve the same thing with

    if(is_category() || is_archive() || is_search()){
    	return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    }else{
        return $title;
    }

    because if I understand it, || means "or". Not sure what best practice is though, I'm afraid.

    Posted 9 years ago #
  6. rkread
    Member

    OK, thanks... I'd guess the briefer the better, but again, this is all new to me.

    indeed, would like to know what is best practice, as well.

    Posted 9 years ago #
  7. Apologies, I have typos everywhere today... what I meant to say was "as I understand it" not "I understand it". Sounded so terribly big-headed >_<

    Posted 9 years ago #
  8. @rkread I'm not sure what happened a while back with your white page except that you probably had a PHP parse error of some sort.

    @flick good call on your suggestion you saw the logic behind what rkread was trying and presented a better way. BTW, I edited your post to reflect your original intentions.

    The best practice here would be the one that accomplishes the task with the least amount of code. Editing the functions.php and hooking into Thematic's functions instead of recreating the other template files is always a good start.

    If you haven't already try developing a good understanding for PHP operators the ones used here are logical operators and how to use them with Conditional Tags Also studying the Template Hierarchy can lead you to a leaner use of conditional logic with WordPress.

    Posted 9 years ago #
  9. @Gene: Thanks very much for editing my post :) I'll be sure to learn more about the (logical) operators as a starting point and will try and build on that.

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.