Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress有条件加载文件_Wordpress - Fatal编程技术网

WordPress有条件加载文件

WordPress有条件加载文件,wordpress,Wordpress,我正在建立一个WP多站点网络。每个站点使用相同的主题。 我想创建一个推荐自定义帖子类型。但是,我只想在一个站点上加载它。 我在functions.php文件中包含了自定义post类型的php文件,这会将其加载到网络中的每个站点 我怎样才能让它只在一个站点上加载?通过某种条件语句 如有任何建议/提示,将不胜感激 Huw从评论中扩展我的答案。这就是如何使用插件创建CPT <?php /* Plugin Name: Your Custom Post Type Description: Add a

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

我怎样才能让它只在一个站点上加载?通过某种条件语句

如有任何建议/提示,将不胜感激


Huw

从评论中扩展我的答案。这就是如何使用插件创建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'=>
,这样你就可以得到你想要的所有字段。

我会创建一个插件,加载自定义帖子类型并在单个站点上激活它。这看起来是一个很好的主意。我以前没有创建过插件;这看起来很简单。Thanks@HuwRowlands这很简单,只要上传到你的插件目录,你就会在管理员的插件列表中看到它。请将我的答案标记为正确答案,如果对您有帮助,请向上投票:)