首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Wordpress的发布框内的编辑帖子页面中添加一个字段?

如何在Wordpress的发布框内的编辑帖子页面中添加一个字段?
EN

Stack Overflow用户
提问于 2012-03-28 20:49:09
回答 2查看 11.9K关注 0票数 20

我想在添加/编辑帖子页面的发布块中添加一个新的复选框。有谁知道怎么做吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-29 20:42:12

我终于找到了解决方案。我希望它对某些人有很好的用处。

代码语言:javascript
复制
add_action( 'post_submitbox_misc_actions', 'publish_in_frontpage' );
function publish_in_frontpage($post)
{
    $value = get_post_meta($post->ID, '_publish_in_frontpage', true);
    echo '<div class="misc-pub-section misc-pub-section-last">
         <span id="timestamp">'
         . '<label><input type="checkbox"' . (!empty($value) ? ' checked="checked" ' : null) . 'value="1" name="publish_in_frontpage" /> Publish to frontpage</label>'
    .'</span></div>';
}

function save_postdata($postid)
{   
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
    if ( !current_user_can( 'edit_page', $postid ) ) return false;
    if(empty($postid) || $_POST['post_type'] != 'article' ) return false;

    if($_POST['action'] == 'editpost'){
        delete_post_meta($postid, 'publish_in_frontpage');
    }

    add_post_meta($postid, 'publish_in_frontpage', $_POST['publish_in_frontpage']);
}
票数 24
EN

Stack Overflow用户

发布于 2012-03-28 23:16:01

使用wordpress的Advanced Custom Fields插件。

票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9907858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档