WordPress2.9新功能有哪些

来源:undefined 2025-01-07 10:27:49 1057

1、文章缩略图

WordPress 2.9 一个比较重头的新功能就是提供了不需要自定义字段的文章缩略图功能,这将对使用者提供很大的便利,但由于一些兼容性的限制,你必须对主题的function.php文件进行修改才能使用这个功能。

在主题的function.php里添加如下代码,你就能使用WordPress的文章缩略图功能。

1

2

3

if ( function_exists( add_theme_support ) ) { //检查WP版本是否为2.9或以上版本 

add_theme_support(post-thumbnails); //如果WP版本符合最低要求则添加文章缩略图 

}

登录后复制

然后在文章列表调用里添加一下代码,用来显示文章缩略图。

1

2

3

if ( (function_exists(has_post_thumbnail)) && (has_post_thumbnail()) ) { 

echo  . the_post_thumbnail() . ; 

}

登录后复制

1

2

3

4

5

6

7

8

9

10

/*如果支持文章缩略图,并且该文章存在缩略图,则显示缩略图,否则显示默认图片*/

  使文章缩略图显示美观的重点是 the_post_thumbnail() 函数的定义,以下代码提供一个简单的说明。

the_post_thumbnail(); //采用默认参数,请参考wp-includes/post-image-template.php文件 

the_post_thumbnail(thumbnail); //小尺寸缩略图 

the_post_thumbnail(medium); //中等缩略图 

the_post_thumbnail(large); //大缩略图 

the_post_thumbnail(medium, array(class => alignleft, alt => alttext)); 

//采用中等缩略图 

//设定图片分辨率为100x100像素,并加上class="alignleft"和描述 

the_post_thumbnail(array(100,100), array(class => alignleft, alt => alttext));

登录后复制

2、侧边栏描述功能

Widget的支持是WordPress一个成功的尝试,它使用户能灵活地定制侧边栏显示的内容,并为插件的调用提供了很大的便利。但一些主题支持自定义多个侧边栏,这就给Widget的正确安装带来困难。侧边栏描述更能的出现就像给支持Widget的区域加上了书签,用户一眼就可以知道所安装的Widget将出现在什么地方。

添加侧边栏描述的方法是在主题的function.php文件里添加如下代码。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

function register_theme_widget_areas() { //定义可以安装Widget的区域 

register_sidebar( array( //定义区域参数 

name => Primary, //侧边栏名称 

id => primary, //侧边栏id 

description => The primary widget area is used as top right sidebar., //侧边栏描述 

before_widget => 

after_widget => 

,

before_title => 

after_title => 

/*以上四行都是定义Widget的样式,基本上和旧版本保持一致*/

) );

}

登录后复制

推荐教程:wordpress教程

以上就是WordPress2.9新功能有哪些的详细内容,更多请关注php中文网其它相关文章!

最新文章