日度归档:2017-01-25

wordpress中为不同位置的缩略图设置不同大小

新建主题函数

打开主题的functions.php文件,加入下面的代码:

// post thumbnail support
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );

if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'post-thumb', 700, 270 );
add_image_size( 'home-thumb', 203, 203, true );
}

上面的代码让主题支持文章缩略图并让WordPress生成2个不同尺寸的缩略图。

“post-thumb”的宽度和高度分别是700px和270px ,“home-thumb”的宽度和高度分别是203px和203px,你可以根据主题手动修改这些数字。

如果有必要,你还可以给图片添加用在其他位置(比如存档页或侧栏文章列表)的尺寸。

home-thumb的最后一个变量是“true”——意思是让WordPress裁剪当前图片并另存为新图片。
继续阅读

wordpress 常见查询方法

方法1

$args = array ( 'post_parent' => 5 );
query_posts( $args );

if ( have_posts() ):
    while ( have_posts() ) :
        the_post();

        // Do stuff with the post content.
        the_title();
        the_permalink(); // Etc.

    endwhile;
else:
    // Insert any content or load a template for no posts found.
endif;

wp_reset_query();

继续阅读