WordPress.org

Support

Support » Plugins and Hacks » Multiple Post Thumbnails » [Resolved] Thumbnails not working in Home page

[Resolved] Thumbnails not working in Home page

  • Hi, I have some problems in retrieving the pages thumbnails in my home page. Everything works properly when thumbanils are displayed in other pages, but related thumbanails disappears when current page is home. How can I solve this problem? I’m actually working on a wp_menu_nav, where there are mixed pages titles with their secondary-image thumbnails.

    This is the code put in function.php file:

    <?php
    
    // nav menu walker
    class My_Walker extends Walker_Nav_Menu
    {
        function start_el(&$output, $item, $depth, $args) {
            global $wp_query;
            $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
            $class_names = $value = '';
    
            $classes = empty( $item->classes ) ? array() : (array) $item->classes;
    
            $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
            $class_names = ' class="' . esc_attr( $class_names ) . '"';
    
            $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
    
            $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
            $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
            $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
            $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
            $attributes .= ' data-id="'. esc_attr( $item->object_id        ) .'"';
            $attributes .= ' data-slug="'. esc_attr(  basename(get_permalink($item->object_id )) ) .'"';
    
    		$post_id = $item->object_id;
    		ob_start();
    		echo '<br><img src="' . MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image', $post_id) . '" />';
    		$myStr = ob_get_contents();
    		ob_end_clean();
    
            $item_output = $args->before;
            $item_output .= '<a'. $attributes . '>';
            $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $myStr . $args->link_after;
            $item_output .= '</a>'; /* This is where I changed things. */
            $item_output .= $args->after;
    
            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
        }}
    
    ?>

    http://wordpress.org/extend/plugins/multiple-post-thumbnails/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Chris Scott

    @chrisscott

    Since this is outside the loop, you likely need to replace get_post_type() with a string value of the post type.

    Yeah, I forgot that. Thank you, I solved my problem. Just replacing get_post_type() with 'page', so that my string became:

    echo '<br><img src="' . MultiPostThumbnails::get_post_thumbnail_url('page', 'secondary-image', $post_id) . '" />';

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Thumbnails not working in Home page’ is closed to new replies.
Skip to toolbar