• Hi,

    I want to display a featured image on my page with different size’s depending on template.

    This is what i have now:
    functions.php

    // Thumbnail support for pages
        add_theme_support('post-thumbnails', array('page'));
    
        add_image_size('customSizeForNews', 300, 0, true);
        add_image_size('FullSize', 940, 340, false );
        add_image_size('DefaultSize', 765, 340, false );

    page:

    <?php
                        if (has_post_thumbnail()) {
    	                    the_post_thumbnail('FullSize');
                        }
                    ?>

    I dont know wye this doesent work, could i have errors in function.php?

    <?php
    
    	// Add RSS links to <head> section
    	automatic_feed_links();
    
        // Add menu support
        if (function_exists('add_theme_support')) {
                register_nav_menus( array( $location => $description ) );
        }
    
    	// Load jQuery
    	if ( !is_admin() ) {
    	   wp_deregister_script('jquery');
    	   wp_register_script('jquery', ("http://code.jquery.com/jquery-1.10.1.min.js"), false);
    	   wp_enqueue_script('jquery');
    
           wp_deregister_script('jqueryMigrate');
    	   wp_register_script('jqueryMigrate', ("http://code.jquery.com/jquery-migrate-1.2.1.min.js"), false);
    	   wp_enqueue_script('jqueryMigrate');
    	}
    
        // Generate page tree
    function sthlmsecurity_page_tree($this_page) {
    	$pagelist = '';
    	if( !$this_page->post_parent ) {
    		$children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
    		if( $children ) {
    			$pagelist .= '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
    			$pagelist .=  $children;
    			$pagelist .= '</li>';
    		}
    	}
    	elseif( $this_page->ancestors ) {
    		// get the top ID of this page. Page ids DESC so top level ID is the last one
    		$ancestor = end( get_post_ancestors($this_page) );
    		$pagelist .= wp_list_pages('title_li=&include='.$ancestor.'&echo=0');
    		$pagelist = str_replace('</li>', '', $pagelist);
    		$pagelist .= wp_list_pages('title_li=&child_of='.$ancestor.'&echo=0') .'</li>';
    	}
    	return $pagelist;
    }
    
    	// Clean up the <head>
    	function removeHeadLinks() {
        	remove_action('wp_head', 'rsd_link');
        	remove_action('wp_head', 'wlwmanifest_link');
        }
        add_action('init', 'removeHeadLinks');
        remove_action('wp_head', 'wp_generator');
    
    	// Declare sidebar widget zone
        if (function_exists('register_sidebar')) {
        	register_sidebar(array(
        		'name' => 'Sidebar Widgets',
        		'id'   => 'sidebar-widgets',
        		'description'   => 'Widgets för sidofältet.',
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
            register_sidebar(array(
        		'name' => 'Kontakt information',
        		'id'   => 'contact-menu',
        		'description'   => 'Kontakt information som visas över menyn.',
        		'before_widget' => '<div id="contact-menu">',
        		'after_widget'  => '</div>'
        	));
        }
    
        // Thumbnail support for pages
        add_theme_support('post-thumbnails', array('page'));
    
        add_image_size('customSizeForNews', 300, 0, true);
        add_image_size('FullSize', 940, 340, true );
        add_image_size('DefaultSize', 765, 340, true );
    
        function excerpt_ellipse($text) {
            return str_replace('[...]', ' <a href="'.get_permalink().'">Läs mer...</a>', $text);
        }
    
        add_filter('get_the_excerpt', 'excerpt_ellipse');
    ?>

  • The topic ‘Featured image different size’ is closed to new replies.