Home > CMS Tutorial > WordPress > body text

What are the new features of WordPress 2.9?

王林
Release: 2019-11-04 11:18:35
Original
2054 people have browsed it

What are the new features of WordPress 2.9?

1. Article thumbnails

One of the more important new features of WordPress 2.9 is the article thumbnail function that does not require custom fields. , which will provide great convenience to users, but due to some compatibility restrictions, you must modify the theme’s function.php file to use this feature.

Add the following code to the theme’s function.php, and you will be able to use the WordPress post thumbnail function.

if ( function_exists( 'add_theme_support' ) ) { //检查WP版本是否为2.9或以上版本 
add_theme_support('post-thumbnails'); //如果WP版本符合最低要求则添加文章缩略图 
}
Copy after login

Then add some code to the article list call to display article thumbnails.

if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { 
echo '' . the_post_thumbnail() . ''; 
}
Copy after login
/*如果支持文章缩略图,并且该文章存在缩略图,则显示缩略图,否则显示默认图片*/
  使文章缩略图显示美观的重点是 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'));
Copy after login

2. Sidebar description function

Widget support is a successful attempt by WordPress, which allows users to flexibly customize the content displayed in the sidebar. And provides great convenience for calling plug-ins. However, some themes support customizing multiple sidebars, which makes it difficult to install the Widget correctly. Sidebar descriptions appear more like bookmarks for widget-supported areas, so users can tell at a glance where the installed widget will appear.

The way to add a sidebar description is to add the following code to the theme's function.php file.

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的样式,基本上和旧版本保持一致*/

) );

}
Copy after login

Recommended tutorial: wordpress tutorial

The above is the detailed content of What are the new features of WordPress 2.9?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template