3

Wordpress自定义栏目使用教程

 2 years ago
source link: http://www.yzipi.com/147.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WordPress自定义栏目(字段)是对Wordpress文章属性一种拓展,一般写文章的时候,后台文章编辑只提供了文章的分类、作者、标签、时间等属性。而自定义栏目可以增加文章其它属性,例如:点赞数和浏览量。而这些属性字段和值都会保存在Wp数据库里面。现在很多Wordpress主题或插件都会使用自字义栏目拓展其功能。

1创建

后台-文章-写文章-显示更多工具和选项(右上角)。 把自定义栏目勾上即可启动 ,而且只要写文章首次加上自定义栏目,以后写文章时只要填上值就可以了。

44.png

如:加上自定义栏目color,值为blue。

2调用

<?php echo get_post_meta($post->ID,"color",true);  ?>

把上面代码,放到模板需要调用这字段的地方,color为你定义的自定义栏目名。

3删除

方法一 :利用主题 functions.php 文件删除

把下面代码加到functions.php中,运行后,删除代码即可。

global $wpdb;

$wpdb->query( "

DELETE FROM $wpdb->postmeta

WHERE `meta_key` = '自定义栏目名称'

" );

方法二 :进入phpMyAdmin,选中数据库,执行下面Sql语句。

DELETE FROM wp_postmeta WHERE meta_key = "栏目名称";

- END -


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK