我在网上找到了一个基础教程,它详细介绍了如何从头开始创建插件,并设置了一个新的自定义帖子类型。我找不到任何基本的优惠券插件来完成我想要的,为什么我决定自己去创建一个。
不幸的是,在完成教程后,我来到了实际查看页面的部分,尽管发布了我的帖子,但却收到了一个“找不到页面”的提示。有谁能检查一下,让我确切地知道我做错了什么?
<?php
/**
* Plugin Name: Coupons
* Plugin URI: http://coupon.net
* Description: A coupon system plugin
* Version: 1.0.0
* Author: Brett Powell
* Author URI: http://coupon.net
**/
// Register the Custom Post Type "Coupon"
function register_cpt_coupon()
{
    $labels = array(
        \'name\' => _x( \'Coupons\', \'coupon\' ),
        \'singular_name\' => _x( \'Coupon\', \'coupon\' ),
        \'add_new\' => _x( \'Add New\', \'coupon\' ),
        \'add_new_item\' => _x( \'Add New Coupon\', \'coupon\' ),
        \'edit_item\' => _x( \'Edit Coupon\', \'coupon\' ),
        \'new_item\' => _x( \'New Coupon\', \'coupon\' ),
        \'view_item\' => _x( \'View Coupon\', \'coupon\' ),
        \'search_items\' => _x( \'Search Coupons\', \'coupon\' ),
        \'not_found\' => _x( \'No coupons found\', \'coupon\' ),
        \'not_found_in_trash\' => _x( \'No coupons found in Trash\', \'coupon\' ),
        \'parent_item_colon\' => _x( \'Parent Coupon:\', \'coupon\' ),
        \'menu_name\' => _x( \'Coupons\', \'coupon\' ),
    );
    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => \'Coupons filterable by company\',
        \'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'genres\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => \'dashicons-format-audio\',
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );
    register_post_type( \'coupon\', $args );
}
add_action( \'init\', \'register_cpt_coupon\' );
// Create Genre Taxonomy type
function genres_taxonomy()
{
    register_taxonomy(
        \'genres\',
        \'coupon\',
        array(
            \'hierarchical\' => true,
            \'label\' => \'Genres\',
            \'query_var\' => true,
            \'rewrite\' => array(
                \'slug\' => \'genre\',
                \'with_front\' => false
            )
        )
    );
}
add_action( \'init\', \'genres_taxonomy\');
// Function used to automatically create Coupon page.
function create_coupon_pages()
{
   //post status and options
    $post = array(
          \'comment_status\' => \'open\',
          \'ping_status\' =>  \'closed\' ,
          \'post_date\' => date(\'Y-m-d H:i:s\'),
          \'post_name\' => \'coupon\',
          \'post_status\' => \'publish\' ,
          \'post_title\' => \'Coupons\',
          \'post_type\' => \'page\',
    );
    //insert page and save the id
    $newvalue = wp_insert_post( $post, false );
    //save the id in the database
    update_option( \'couponpage\', $newvalue );
}
// // Activates function if plugin is activated
register_activation_hook( __FILE__, \'create_coupon_pages\');
?>