我开始为我的网站构建一个插件,但我得到错误的所有方法 标题全部已发送 我试图以不同的方式改变我的代码,但我总是得到同样的错误。
插件在激活期间生成了3个意外结果字符。如果您发现“已发送标头”消息,Feed问题或其他问题,请尝试禁用或删除此插件。
我已经建议更改,现在菜单工作和发布类型,但我仍然留下所有准备发送的标题的问题,我已经尝试打开原子编辑器并保存,但它解决问题
这是完整的代码
<?php
/*
Plugin Name: Post type linksmd.
Version: 1.0
Description: post type linksmd.
Plugin URI: https://mediaads.eu/
Author: Helder Ventura
Author URI: https://mediaads.eu
Version: (standalone)
Usage: install activate and done
*/
// Our custom post type function
function create_posttype() {
register_post_type( 'linksmdmd',
// CPT Options
array(
'labels' => array(
'name' => __( 'linksmd' ),
'singular_name' => __( 'linksmd' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'linksmd'),
)
);
}
/*
* Creating a function to create our CPT
*/
function custom_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'linksmd', 'Post Type General Name', 'Divi'
),
'singular_name' => _x( 'Link', 'Post Type Singular Name', 'Divi'
),
'menu_name' => __( 'linksmd', 'Divi' ),
'parent_item_colon' => __( 'Parent Link', 'Divi' ),
'all_items' => __( 'All linksmd', 'Divi' ),
'view_item' => __( 'View Link', 'Divi' ),
'add_new_item' => __( 'Add New Link', 'Divi' ),
'add_new' => __( 'Add New', 'Divi' ),
'edit_item' => __( 'Edit Link', 'Divi' ),
'update_item' => __( 'Update Link', 'Divi' ),
'search_items' => __( 'Search Link', 'Divi' ),
'not_found' => __( 'Not Found', 'Divi' ),
'not_found_in_trash' => __( 'Not found in Trash', 'Divi' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'linksmd', 'Divi' ),
'description' => __( 'Link news and reviews', 'Divi' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
// Registering your Custom Post Type
register_post_type( 'linksmd', $args );
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( 'init', 'custom_post_type', 0 );
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
function wpb_postsbycategory() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'linksmd', 'posts_per_page' => 10 ) );
// The Loop
if ( $the_query->have_posts() ) {
$string .= '<ul class="postsbycategory widget_recent_entries">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if ( has_post_thumbnail() ) {
$string .= '<li>';
$string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
} else {
// if no featured image is found
$string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
}
} else {
// no posts found
}
$string .= '</ul>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('categoryposts', 'wpb_postsbycategory');
// Enable shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');
?>
答案 0 :(得分:1)
激活期间意外结果的3个字符
最可能的BOM单一,在Atom编辑器中打开此文件并重新保存。
以防万一
您的插件只有resiter_post_type('Links'
,您没有必要。做
曾经。
'category_name' => 'Links'
中的 query_posts
,您确定要使用自定义帖子类型而不是自定义分类吗?
将该别名保持为小型,机器人Links
,但links
。更多的是,将links
更改为其他内容。就我记忆而言,links
是一个遗产类别,并且你在体育上会遇到问题。