WordPress有条件地加载文件

时间:2013-09-19 13:59:11

标签: wordpress

我正在构建一个WP Multisite网络。每个站点使用相同的主题。 我想创建一个Testimonials自定义帖子类型。但是,我只想在一个网站上加载它。 我在functions.php文件中包含自定义帖子类型的php文件,这将它加载到网络中的每个站点。

如何只在一个网站上加载?通过某种条件语句?

任何建议/提示都将不胜感激。

1 个答案:

答案 0 :(得分:1)

从评论中扩展我的答案。这就是你如何使用插件制作CPT。

<?php
/*
Plugin Name: Your Custom Post Type
Description: Add a custom post type
Author: Oskar Hane
Version: 1.0
Author URI: http://oskarhane.com
*/


// Register Post Type
add_action( 'init', 'registerMyCustomPostType' );
function registerMyCustomPostType()
{
    $labels_cpt = array(
        'name' => _x('My Posts', 'post type general name'),
        'singular_name' => _x('My Post', 'post type singular name'),
        'add_new' => _x('Add new', 'kurser'),
        'add_new_item' => __('Add new item'),
        'edit_item' => __('Edit item'),
        'new_item' => __('New item'),
        'view_item' => __('View item'),
        'search_items' => __('Search items' ),
        'not_found' =>  __('No items found'),
        'not_found_in_trash' => __('No items in trash'), 
        'parent_item_colon' => ''
          );

    register_post_type('my_post_type', array(
        'labels' => $labels_cpt,
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => true,
        'exclude_from_search' => true,
        'show_in_admin_bar' => true,
        'query_var' => true,
        'has_archive' => true,
        'supports' => array('title', 'editor')
    ));   
}
?>

只需为网络激活它,然后为您想要的网站安装/激活它。

并确保检查所有值,尤其是'supports' =>,以便获得所需的所有字段。

相关问题