ThemeShaper Forums » Thematic

[closed]

Insert related post image thumbnail to category and tag pages

(12 posts)
  • Started 10 years ago by Bluesky
  • Latest reply from Bluesky
  • This topic is not resolved
  1. Bluesky
    Member

    Hello community...
    I am building my blog through your great tutorial !! So far so good...I succeedeed to manage.
    BUT...
    I can not figure out how to insert the thumbnail of each post inside the post when I go to category page or tag page.

    I would also eventually like to have a hook on each image of my posts when I need it...
    Where can I get the solution, the tip, the tut may'be....?
    Thank you for your help,
    Cheers,

    Posted 10 years ago #
  2. one way for sure would be to write your own tag and category loops. for this i usually go into the thematic library folder, extensions, and open up content extensions. find the category loop and copy the function into your functions.php.

    //add capability to use WP thumbnails
    add_theme_support( 'post-thumbnails' );
    
    //wrap thumbnails w link to post
    
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    
    $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
    
    return $html;
    }
    
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    
    //remove the current category loop from its hook
    function remove_thematic_action() {
    remove_action('thematic_categoryloop','thematic_category_loop');
    }
    add_action('init','remove_thematic_action');
    
    // My New Category Loop
    function my_category_loop() {
    while (have_posts()) : the_post(); 
    
    thematic_abovepost(); ?>
    
    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    <?php thematic_postheader(); ?>
    
    //if it has a thumbnail post it here
    <div class="thumbnail">
    <?php
    if ( has_post_thumbnail() ) {
    the_post_thumbnail( 'thumbnail' );
     } else {
    	echo '<img src="default-image.png" alt="Example Image" title="Example" />';
    
    } ?>
    </div>
    <div class="entry-content">
    <?php thematic_content(); ?>
    
    </div>
    <?php thematic_postfooter(); ?>
    </div><!-- .post -->
    
    <?php
    thematic_belowpost();
    
    endwhile;
    }
    
    add_action('thematic_categoryloop', 'my_category_loop');

    you can then do a similar thing for all the loops: tag, author, search, etc. download and take a look at Gallery for a good example of custom loops. fair warning... i didn't test this, so there could be a mistake, but it ought to set you in the right direction. i think there is another way you could do this.... by filtering the entry-title i think, maybe someone else will post it and you can choose which you find easier.

    see http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature for more info on thumbnails in WP.

    Posted 10 years ago #
  3. Bluesky
    Member

    Thank you !!! I just read your answer and will work on it. I let you know. Link could be valuable to.

    Posted 10 years ago #
  4. Bluesky
    Member

    Well...this does not start very well. I do not have any thematic library folder, extensions.
    Sometimes I am confused with thematic. I wonder if it the same files as the ones provided in the tutorial or if I should simply have downloaded the thematic at once.

    So in the theme tutorial, here is the code for the category :

    // For category lists on category archives: Returns other categories except the current one (redundant)
    function cats_meow($glue) {
    $current_cat = single_cat_title( '', false );
    $separator = "\n";
    $cats = explode( $separator, get_the_category_list($separator) );
    foreach ( $cats as $i => $str ) {
    if ( strstr( $str, ">$current_cat<" ) ) {
    unset($cats[$i]);
    break;
    }
    }
    if ( empty($cats) )
    return false;

    return trim(join( $glue, $cats ));
    } // end cats_meow

    add_filter('thematic_postheader_posttitle', 'my_post_title');

    How could I work directly from there ?

    Posted 10 years ago #
  5. i swear i posted to this yesterday... akismet must be getting me again.

    i have no clue what that function is or is trying to do. but you DO definitely have a content-extensions file in the library folder. it is in Thematic. you should download thematic, unzip it and that way you will have said folder for reference. i look in there all the time. what tutorial are you looking at?

    you do not make any edits there however. i usually just copy the functions into my child's functions.php file (and rename them) or sometimes i only need to know the NAME of a certain function, etc.

    try pasting my above code into your functions.php file and let me know what happens.

    Posted 10 years ago #
  6. pelayo.mao
    Member

    The code above, inserted in functions.php doesnt work fine:

    when trying to load the index page it returns this message:

    Fatal error: Cannot redeclare my_post_image_html() (previously declared in /docroot/wp/wp-content/plugins/super-post-and-page-plugin/super_page_widget.php:179) in /docroot/wp/wp-content/themes/thematic/functions.php on line 32

    Posted 10 years ago #
  7. pelayo.mao
    Member

    I had a plugin enabled... now no error, but nothing changes, whats the next step?

    This is where I want thumbnails: http://www.cartom.com/wp/?page_id=127

    Posted 10 years ago #
  8. Bluesky
    Member

    Hello Helgatheviking and thanks for keeping up with this...
    Well I actually copied your code...but nothing happened.
    The tutorial is actually coming from themeshaper.com
    I am gonna have to check out thematic....

    I wonder if some people from theme shaper sometimes pass by this forum ....
    Thank you again anyway a lot for your help :-)
    Cheers,

    Posted 10 years ago #
  9. ok i found the other function i was thinking of when replying to another post and then i tweaked it to use myself for thumbnails in excerpts.

    add_theme_support( 'post-thumbnails' );
    
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    	$html = '<div class="thumbnail"><a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a></div>';
    	return $html;
    }
    
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    
    // modify excerpts
    // add read more links to everything, add thumbnails and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	if ( has_post_thumbnail() ) {
    		$child_excerpt =  the_post_thumbnail( 'thumbnail' ) . '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	else {
    		$child_excerpt = '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	return $child_excerpt;
     }
    
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    this should work everywhere the theme uses excerpts. if you only want thumbnails on certain sections would need to add some more conditional logic. hope this helps.

    Posted 10 years ago #
  10. Bluesky
    Member

    Hello Helgatheviking !
    Here am I again after so long...
    I spent it trying to solve this, changed framework, came back, changed again...to finally install Thematic.
    So I followed again your posts , now that I have the same files.
    So far, I went into the thematic library folder, extensions, and open up content extensions. Indeed I found this time the category loop and copied the function into my functions.php as followed :
    // The Loop
    function thematic_categoryloop() {
    do_action('thematic_categoryloop');
    } // end thematic_categoryloop

    My functions.php file looks like this now :

    <?php

    // Getting Theme and Child Theme Data
    // Credits: Joern Kretzschmar

    $themeData = get_theme_data(TEMPLATEPATH . '/style.css');
    $version = trim($themeData['Version']);
    if(!$version)
    $version = "unknown";

    $ct=get_theme_data(STYLESHEETPATH . '/style.css');
    $templateversion = trim($ct['Version']);
    if(!$templateversion)
    $templateversion = "unknown";

    // set theme constants
    define('THEMENAME', $themeData['Title']);
    define('THEMEAUTHOR', $themeData['Author']);
    define('THEMEURI', $themeData['URI']);
    define('THEMATICVERSION', $version);

    // set child theme constants
    define('TEMPLATENAME', $ct['Title']);
    define('TEMPLATEAUTHOR', $ct['Author']);
    define('TEMPLATEURI', $ct['URI']);
    define('TEMPLATEVERSION', $templateversion);

    // load jQuery
    wp_enqueue_script('jquery');

    // Path constants
    define('THEMELIB', TEMPLATEPATH . '/library');

    // Create Theme Options Page
    require_once(THEMELIB . '/extensions/theme-options.php');

    // Load legacy functions
    require_once(THEMELIB . '/legacy/deprecated.php');

    // Load widgets
    require_once(THEMELIB . '/extensions/widgets.php');

    // Load custom header extensions
    require_once(THEMELIB . '/extensions/header-extensions.php');

    // Load custom content filters
    require_once(THEMELIB . '/extensions/content-extensions.php');

    // Load custom Comments filters
    require_once(THEMELIB . '/extensions/comments-extensions.php');

    // Load custom Widgets
    require_once(THEMELIB . '/extensions/widgets-extensions.php');

    // Load the Comments Template functions and callbacks
    require_once(THEMELIB . '/extensions/discussion.php');

    // Load custom sidebar hooks
    require_once(THEMELIB . '/extensions/sidebar-extensions.php');

    // Load custom footer hooks
    require_once(THEMELIB . '/extensions/footer-extensions.php');

    // Add Dynamic Contextual Semantic Classes
    require_once(THEMELIB . '/extensions/dynamic-classes.php');

    // Need a little help from our helper functions
    require_once(THEMELIB . '/extensions/helpers.php');

    // Load shortcodes
    require_once(THEMELIB . '/extensions/shortcodes.php');

    // Adds filters for the description/meta content in archives.php
    add_filter( 'archive_meta', 'wptexturize' );
    add_filter( 'archive_meta', 'convert_smilies' );
    add_filter( 'archive_meta', 'convert_chars' );
    add_filter( 'archive_meta', 'wpautop' );

    // Remove the WordPress Generator – via http://blog.ftwr.co.uk/archives/2007/10/06/improving-the-wordpress-generator/
    function thematic_remove_generators() { return ''; }
    if (apply_filters('thematic_hide_generators', TRUE)) {
    add_filter('the_generator','thematic_remove_generators');
    }

    // The Loop I JUST ADDED FROM THE EXTENSIONS
    function thematic_categoryloop() {
    do_action('thematic_categoryloop');
    } // end thematic_categoryloop

    // Translate, if applicable
    load_theme_textdomain('thematic', THEMELIB . '/languages');

    $locale = get_locale();
    $locale_file = THEMELIB . "/languages/$locale.php";
    if ( is_readable($locale_file) )
    require_once($locale_file);

    ?>

    Next step would be to add the following code ??
    add_theme_support( 'post-thumbnails' );

    function my_post_image_html( $html, $post_id, $post_image_id ) {
    $html = '<div class="thumbnail">' . $html . '</div>';
    return $html;
    }

    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

    // modify excerpts
    // add read more links to everything, add thumbnails and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    if ( has_post_thumbnail() ) {
    $child_excerpt = the_post_thumbnail( 'thumbnail' ) . '<p>' . $post_excerpt . '</p>' . '<p class="readmore">ID) . '">' . 'Continue Reading &raquo' . '</p>';
    }
    else {
    $child_excerpt = '<p>' . $post_excerpt . '</p>' . '<p class="readmore">ID) . '">' . 'Continue Reading &raquo' . '</p>';
    }

    return $child_excerpt;
    }

    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    Posted 9 years ago #
  11. so doe that work? also, i don't think you need any/all of the following code, unless you've made some modifications that I can't see. Thematic will do all that automatically without the need for you to paste it into your functions file.

    // Getting Theme and Child Theme Data
    // Credits: Joern Kretzschmar
    
    $themeData = get_theme_data(TEMPLATEPATH . '/style.css');
    $version = trim($themeData['Version']);
    if(!$version)
    $version = "unknown";
    
    $ct=get_theme_data(STYLESHEETPATH . '/style.css');
    $templateversion = trim($ct['Version']);
    if(!$templateversion)
    $templateversion = "unknown";
    
    // set theme constants
    define('THEMENAME', $themeData['Title']);
    define('THEMEAUTHOR', $themeData['Author']);
    define('THEMEURI', $themeData['URI']);
    define('THEMATICVERSION', $version);
    
    // set child theme constants
    define('TEMPLATENAME', $ct['Title']);
    define('TEMPLATEAUTHOR', $ct['Author']);
    define('TEMPLATEURI', $ct['URI']);
    define('TEMPLATEVERSION', $templateversion);
    
    // load jQuery
    wp_enqueue_script('jquery');
    
    // Path constants
    define('THEMELIB', TEMPLATEPATH . '/library');
    
    // Create Theme Options Page
    require_once(THEMELIB . '/extensions/theme-options.php');
    
    // Load legacy functions
    require_once(THEMELIB . '/legacy/deprecated.php');
    
    // Load widgets
    require_once(THEMELIB . '/extensions/widgets.php');
    
    // Load custom header extensions
    require_once(THEMELIB . '/extensions/header-extensions.php');
    
    // Load custom content filters
    require_once(THEMELIB . '/extensions/content-extensions.php');
    
    // Load custom Comments filters
    require_once(THEMELIB . '/extensions/comments-extensions.php');
    
    // Load custom Widgets
    require_once(THEMELIB . '/extensions/widgets-extensions.php');
    
    // Load the Comments Template functions and callbacks
    require_once(THEMELIB . '/extensions/discussion.php');
    
    // Load custom sidebar hooks
    require_once(THEMELIB . '/extensions/sidebar-extensions.php');
    
    // Load custom footer hooks
    require_once(THEMELIB . '/extensions/footer-extensions.php');
    
    // Add Dynamic Contextual Semantic Classes
    require_once(THEMELIB . '/extensions/dynamic-classes.php');
    
    // Need a little help from our helper functions
    require_once(THEMELIB . '/extensions/helpers.php');
    
    // Load shortcodes
    require_once(THEMELIB . '/extensions/shortcodes.php');
    
    // Adds filters for the description/meta content in archives.php
    add_filter( 'archive_meta', 'wptexturize' );
    add_filter( 'archive_meta', 'convert_smilies' );
    add_filter( 'archive_meta', 'convert_chars' );
    add_filter( 'archive_meta', 'wpautop' );
    
    // Remove the WordPress Generator – via http://blog.ftwr.co.uk/archives/2007/10/06/improving-the-wordpress-generator/
    function thematic_remove_generators() { return ''; }
    if (apply_filters('thematic_hide_generators', TRUE)) {
    add_filter('the_generator','thematic_remove_generators');
    }
    
    // The Loop I JUST ADDED FROM THE EXTENSIONS
    function thematic_categoryloop() {
    do_action('thematic_categoryloop');
    } // end thematic_categoryloop
    
    // Translate, if applicable
    load_theme_textdomain('thematic', THEMELIB . '/languages');
    
    $locale = get_locale();
    $locale_file = THEMELIB . "/languages/$locale.php";
    if ( is_readable($locale_file) )
    require_once($locale_file);
    
    ?>
    Posted 9 years ago #
  12. Bluesky
    Member

    Hi !
    No it does not work
    But I just guessed ( beginners always take a tremendous time to get it I guess ??!!) that I might have modified the wrong functions.php
    The one above is the functions.php located in the Thematic folder, and does not look like functions.php I am used to see bbtw.
    So I discovered that I need to modify the functions.php located in thematic/thematicsamplechildtheme/functions.php

    I think all my problems came from this...I am gonna try again

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.