使用多种自定义帖子类型(骨骼主题)

时间:2015-04-15 15:59:12

标签: php wordpress custom-post-type

我为我的骨骼主题制作了自定义内容类型,但当我尝试添加其他自定义内容类型时,我的网站停止工作,只显示空白页面。

我认为它与require_once或函数名称有关。

这是我的function.php

require_once( 'library/team.php' );
require_once( 'library/partners.php' );

这是我的自定义帖子PHP文件。

function custom_post_team()
function custom_post_partners()

我做错了吗?

编辑:从文件中添加了php。

Postype:"合作伙伴"     

add_action( 'after_switch_theme', 'bones_flush_rewrite_rules' );


function bones_flush_rewrite_rules() {
    flush_rewrite_rules();
}

function custom_post_partners() { 

    register_post_type( 'partners', 

        array( 'labels' => array(
            'name' => __( 'Partners', 'bonestheme' ), 
            'singular_name' => __( 'Partners', 'bonestheme' ), 
            'all_items' => __( 'Partners', 'bonestheme' ), 
            'add_new' => __( 'Add New', 'bonestheme' ), 
            'add_new_item' => __( 'Add New Partner', 'bonestheme' ), 
            'edit' => __( 'Edit', 'bonestheme' ), 
            'edit_item' => __( 'Edit Post Types', 'bonestheme' ), 
            'new_item' => __( 'New Post Type', 'bonestheme' ), 
            'view_item' => __( 'View Post Type', 'bonestheme' ), 
            'search_items' => __( 'Search Post Type', 'bonestheme' ),
            'not_found' =>  __( 'Nothing found in the Database.', 'bonestheme' ), 
            'not_found_in_trash' => __( 'Nothing found in Trash', 'bonestheme' ), 
            'parent_item_colon' => ''
            ), 
            'description' => __( 'Partners', 'bonestheme' ), 
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 8, 
            'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', 
            'rewrite'   => array( 'slug' => 'partners', 'with_front' => false ), 
            'has_archive' => false, 
            'capability_type' => 'post',
            'hierarchical' => false,

            'supports' => array( 'title', 'editor', 'thumbnail', 'sticky')
        ) 
    ); 

}
    add_action( 'init', 'custom_post_partners');    

?>

Posttype:team

<?php

add_action( 'after_switch_theme', 'bones_flush_rewrite_rules' );

function bones_flush_rewrite_rules() {
    flush_rewrite_rules();
}

function custom_post_team() { 

    register_post_type( 'team', 

        array( 'labels' => array(
            'name' => __( 'Team', 'bonestheme' ), 
            'singular_name' => __( 'Team', 'bonestheme' ), 
            'all_items' => __( 'Team', 'bonestheme' ), 
            'add_new' => __( 'Add New', 'bonestheme' ), 
            'add_new_item' => __( 'Add New Team Member', 'bonestheme' ), 
            'edit' => __( 'Edit', 'bonestheme' ), 
            'edit_item' => __( 'Edit Post Types', 'bonestheme' ), 
            'new_item' => __( 'New Post Type', 'bonestheme' ), 
            'view_item' => __( 'View Post Type', 'bonestheme' ), 
            'search_items' => __( 'Search Post Type', 'bonestheme' ),
            'not_found' =>  __( 'Nothing found in the Database.', 'bonestheme' ), 
            'not_found_in_trash' => __( 'Nothing found in Trash', 'bonestheme' ), 
            'parent_item_colon' => ''
            ), 
            'description' => __( 'Team', 'bonestheme' ), 
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 8, 
            'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', 
            'rewrite'   => array( 'slug' => 'team', 'with_front' => false ), 
            'has_archive' => false, 
            'capability_type' => 'post',
            'hierarchical' => false,

            'supports' => array( 'title', 'editor', 'thumbnail', 'sticky')
        ) 
    ); 

}

    add_action( 'init', 'custom_post_team');

?>

的functions.php

<?php

require_once( 'library/bones.php' );

function bones_ahoy() {

  add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor-style.css' );

  load_theme_textdomain( 'bonestheme', get_template_directory() . '/library/translation' );

    require_once( 'library/team.php' );
    require_once( 'library/partners.php' );

  add_action( 'init', 'bones_head_cleanup' );
  add_filter( 'wp_title', 'rw_title', 10, 3 );
  add_filter( 'the_generator', 'bones_rss_version' );
  add_filter( 'wp_head', 'bones_remove_wp_widget_recent_comments_style', 1 );
  add_action( 'wp_head', 'bones_remove_recent_comments_style', 1 );
  add_filter( 'gallery_style', 'bones_gallery_style' );

  add_action( 'wp_enqueue_scripts', 'bones_scripts_and_styles', 999 );

  bones_theme_support();

  add_action( 'widgets_init', 'bones_register_sidebars' );

  add_filter( 'the_content', 'bones_filter_ptags_on_images' );
  add_filter( 'excerpt_more', 'bones_excerpt_more' );

} 

add_action( 'after_setup_theme', 'bones_ahoy' );


if ( ! isset( $content_width ) ) {
    $content_width = 640;
}

add_image_size( 'bones-thumb-600', 600, 150, true );
add_image_size( 'bones-thumb-300', 300, 100, true );
add_image_size( 'news-thumb-290', 290, 190, true );
add_image_size( 'news-thumb-140', 140, 84, true );

add_filter( 'image_size_names_choose', 'bones_custom_image_sizes' );

function bones_custom_image_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'bones-thumb-600' => __('600px by 150px'),
        'bones-thumb-300' => __('300px by 100px'),
        'news-thumb-290' => __('290px by 190px'),
        'news-thumb-140' => __('140px by 84px'),
    ) );
}

function bones_theme_customizer($wp_customize) {
}

add_action( 'customize_register', 'bones_theme_customizer' );


function arphabet_widgets_init() {

  register_sidebar( array(
    'name'          => 'Footer',
    'id'            => 'footer-area',
    'before_widget' => '<div>',
    'after_widget'  => '</div>',
    'before_title'  => '<div class="marquee-title">',
    'after_title'   => '</div>',
  ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );

function bones_register_sidebars() {
    register_sidebar(array(
        'id' => 'sidebar1',
        'name' => __( 'Sidebar 1', 'bonestheme' ),
        'description' => __( 'The first (primary) sidebar.', 'bonestheme' ),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',
    ));

} 


function bones_comments( $comment, $args, $depth ) {
   $GLOBALS['comment'] = $comment; ?>
  <div id="comment-<?php comment_ID(); ?>" <?php comment_class('cf'); ?>>
    <article  class="cf">
      <header class="comment-author vcard">
        <?php

        ?>
        <?php  ?>
        <?php

          $bgauthemail = get_comment_author_email();
        ?>
        <img data-gravatar="http://www.gravatar.com/avatar/<?php echo md5( $bgauthemail ); ?>?s=40" class="load-gravatar avatar avatar-48 photo" height="40" width="40" src="<?php echo get_template_directory_uri(); ?>/library/images/nothing.gif" />
        <?php ?>
        <?php printf(__( '<cite class="fn">%1$s</cite> %2$s', 'bonestheme' ), get_comment_author_link(), edit_comment_link(__( '(Edit)', 'bonestheme' ),'  ','') ) ?>
        <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'bonestheme' )); ?> </a></time>

      </header>
      <?php if ($comment->comment_approved == '0') : ?>
        <div class="alert alert-info">
          <p><?php _e( 'Your comment is awaiting moderation.', 'bonestheme' ) ?></p>
        </div>
      <?php endif; ?>
      <section class="comment_content cf">
        <?php comment_text() ?>
      </section>
      <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    </article>
  <?php ?>
<?php
} 


function bones_fonts() {
  wp_enqueue_style('googleFonts', 'http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic');
}

add_action('wp_enqueue_scripts', 'bones_fonts');

    add_theme_support( 'html5', array(
        'comment-list',
        'search-form',
        'comment-form'
    ) );

?>

1 个答案:

答案 0 :(得分:0)

我通过将不同的帖子类型组合到一个文件而不是单独的文件中来设法解决了这个问题。立即行动。