我怎么才能让我的变态出现呢?

时间:2017-08-18 作者:manoukmade

我对插件开发相当陌生,但在编码方面有经验。我已经阅读了一些教程,并设法将我的帖子类型设置为幻灯片,但我想添加一个元框来放置URL。

然而,它并没有显示出来,我跟随的许多教程都说我现在应该看到它了。有人能帮忙吗?下面的教程、代码和图片链接。

后续教程:https://www.sitepoint.com/real-world-example-wordpress-plugin-development/

我也尝试过其他教程(来自:themefoundation and code.tutsplus),但它们似乎都不能与我已经编写的内容配合使用

(文本为荷兰语抱歉)It does not appear on here

    <?php

function register_slide_content_type(){

    $labels = array(
        \'name\' => _x( \'Slides\', \'slideshow\' ),
        \'singular_name\' => _x( \'Slides\', \'slideshow\' ),
        \'add_new\' => _x( \'Nieuwe Slide\', \'slideshow\' ),
        \'add_new_item\' => _x( \'Nieuwe Slide Toevoegen\', \'slideshow\' ),
        \'edit_item\' => _x( \'Edit Slide\', \'slideshow\' ),
        \'new_item\' => _x( \'Nieuwe Slide\', \'slideshow\' ),
        \'view_item\' => _x( \'Bekijk Slide\', \'slideshow\' ),
        \'search_items\' => _x( \'Zoek Slides\', \'slideshow\' ),
        \'not_found\' => _x( \'Geen slides gevonden\', \'slideshow\' ),
        \'not_found_in_trash\' => _x( \'Geen slides gevonden in prullenbak\', \'slideshow\' ),
        \'parent_item_colon\' => _x( \'Parent Slide:\', \'slideshow\' ),
        \'menu_name\' => _x( \'Slideshow\', \'slideshow\' ),
    );

   //arguments for post type
       $args = array(
           \'labels\'            => $labels,
           \'hierarchical\' => true,
           \'description\' => \'Slides voor op de website\',
           \'taxonomies\' => array( \'plaatsen\' ),
           \'public\'            => true,
           \'publicly_queryable\'=> true,
           \'show_ui\'           => true,
           \'show_in_nav\'       => true,
           \'query_var\'         => true,
           \'supports\'          => array(\'title\',\'thumbnail\',\'editor\'),
           \'has_archive\'       => true,
           \'menu_position\'     => 5,
           \'show_in_admin_bar\' => true,
           \'menu_icon\'         => \'dashicons-images-alt2\',
           \'rewrite\'            => array(\'slug\' => \'slides\', \'with_front\' => \'true\')
       );

    register_post_type( \'slideshow\', $args );
}

add_action( \'init\', \'register_slide_content_type\' );

function plaatsen_taxonomy() {
    register_taxonomy(
        \'plaatsen\',
        \'slideshow\',
        array(
            \'hierarchical\' => true,
            \'label\' => \'Plaatsingen\',
            \'query_var\' => true,
            \'rewrite\' => array(
                \'slug\' => \'plaatsen\',
                \'with_front\' => false
            )
        )
    );
}
add_action( \'init\', \'plaatsen_taxonomy\');


add_action( \'load-post.php\', \'slide_post_meta_boxes_setup\' );
add_action( \'load-post-new.php\', \'slide_post_meta_boxes_setup\' );

function slide_post_meta_boxes_setup() {

  add_action( \'add_meta_boxes\', \'slide_add_post_meta_boxes\' );
}

function slide_add_post_meta_boxes() {
  add_meta_box(
    \'pukkemukslideshow\',      // Unique ID
    __( \'Slideshow\', \'example\' ),    // Title
    \'slide_post_class_meta_box\',   // Callback function
    \'post_type\',         // Admin page (or post type)
    \'advanced\',         // Context
    \'high\'         // Priority
  );
}


function slide_post_class_meta_box( $post ) { ?>
  <p>
    <label for="slide-post-class">Plak hier de URL waar de slide naar moet wijzen.</label>
    <br />
    <input type="text" name="slide-post-class" id="slide-post-class" value="<?php echo esc_attr( get_post_meta( $post->ID, \'slide_post_class\', true ) ); ?>" size="30" />
  </p>
<?php } 

?>

1 个回复
SO网友:manoukmade

由于@howdy\\u mcGee的评论,我成功地使其生效。我没有注意到我必须调用它的特定帖子类型名称。我的代码现在是这样的,它显示出来了!

    function slide_add_post_meta_boxes() {
  add_meta_box(
    \'pukkemukslideshow\',      // Unique ID
    __( \'Slideshow\', \'example\' ),    // Title
    \'slide_post_class_meta_box\',   // Callback function
    \'slideshow\',         // Admin page (or post type)
    \'advanced\',         // Context
    \'high\'         // Priority
  );
}

结束

相关推荐

从Metabox数字中去掉十进制

我正在Wordpress网站上为一位客户展示几个房产清单及其相关价格。当我在开发人员创建的元数据库中输入数字时,它会去掉所有的小数。因此,如果我输入16.50,当页面保存时,它会立即变为1650。我希望它能显示2个小数。我做了一些研究,但我对PHP/Wordpress的知识还不够渊博,无法理解。开发人员指示我调整代码的格式,但只需在数字上添加2个小数,以显示1650.00,而不是我想要的16.50。在元数据库中输入小数点后,它会立即被删除。我觉得好像在某个地方定义了某种东西,从这个输入字段中去掉了所有的小