• April 25, 2018

    Use wordpress’s in-built “featured image” (can be set on post’s editing page in wordpress admin).
    On the page displaying the excerpts:

    <div id="excerpts">
        <?php
        $args = array( 'numberposts' => 3, 'category'=> '1,3,5' ); }
        // set number of excepts to show
        // and optionally restrict to certain categories
        $posts = get_posts($args);
        foreach($posts as $post) : setup_postdata($post);
        ?>
        <div class="single-excerpt">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php if ( has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
            <!-- displays thumbnail if it exists -->
            <p><?php the_excerpt();?></p>
        </div><!-- single-excerpt -->
        <?php endforeach; ?>
    </div><!-- excerpts -->

    In your theme’s functions.php:

    if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
    if ( function_exists( 'add_image_size' ) ) { 
        add_image_size( 'excerpt-thumb', 0, 100, false );
        // define excerpt-thumb size here
        // in the example: 100px wide, height adjusts automatically, no cropping
    }
    
    function new_excerpt_length($length) {
        return 42;
        // define length of excerpt in number of words
    }
    add_filter('excerpt_length', 'new_excerpt_length');


เวอไนน์ไอคอร์ส

ประหยัดเวลากว่า 100 เท่า!






เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์

Categories