我在制作帖子类型和帖子类型元框后制作自定义插件。现在,我正在为单个页面中的高级内容制作单个文件。 我已经在自定义插件中制作了 single.php 和 functions.php 文件,我在其中提供了链接或调用了 single.php 文件。功能文件,但没有任何变化,即使错误也没有显示。 如果我在单个文件中执行 var_dump ,将不会显示任何错误信息,因为我是第一次制作自定义插件,因此我不知道。 有人可以向我建议正确的方向吗?
在此文件插件类型中创建的plugin核心文件( core-file.php )
<?php
/*
Plugin Name: d4d Jobs
Plugin URI: http://d4djobs.com/
Description: Declares a plugin that will create a custom post type
displaying d4d Jobs.
Version: 1.0
Author: Aivah Developer
Author URI: http://aivah.com/
License: GPLv2
*/
/**
* Register a custom post type called "Jobs".
*
* @see get_post_type_labels() for label keys.
*/
function wpdocs_codex_jobs_init() {
$labels = array(
'name' => _x( 'Jobs', 'Post type general name',
'textdomain' ),
'singular_name' => _x( 'Jobs', 'Post type singular name',
'textdomain' ),
'menu_name' => _x( 'Jobs', 'Admin Menu text', 'textdomain'
),
'name_admin_bar' => _x( 'Jobs', 'Add New on Toolbar',
'textdomain' ),
'add_new' => __( 'Add New', 'textdomain' ),
'add_new_item' => __( 'Add New Jobs', 'textdomain' ),
'new_item' => __( 'New Jobs', 'textdomain' ),
'edit_item' => __( 'Edit Jobs', 'textdomain' ),
'view_item' => __( 'View Jobs', 'textdomain' ),
'all_items' => __( 'All Jobs', 'textdomain' ),
'search_items' => __( 'Search Jobs', 'textdomain' ),
'parent_item_colon' => __( 'Parent Jobs:', 'textdomain' ),
'not_found' => __( 'No Jobs found.', 'textdomain' ),
'not_found_in_trash' => __( 'No Jobs found in Trash.', 'textdomain'
),
'featured_image' => _x( 'Jobs Cover Image', 'Overrides the
“Featured Image” phrase for this post type. Added in 4.3',
'textdomain' ),
'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set
featured image” phrase for this post type. Added in 4.3',
'textdomain' ),
'remove_featured_image' => _x( 'Remove cover image', 'Overrides the
“Remove featured image” phrase for this post type. Added in 4.3',
'textdomain' ),
'use_featured_image' => _x( 'Use as cover image', 'Overrides the
“Use as featured image” phrase for this post type. Added in 4.3',
'textdomain' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'jobs' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-clipboard',
'supports' => array( 'title', 'editor', 'author',
'thumbnail', 'excerpt', 'comments' ),
);
register_post_type( 'jobs', $args );
}
add_action( 'init', 'wpdocs_codex_jobs_init' );
require_once dirname( __FILE__ ) . '/includes/meta-generator.php';
在此文件插件文章类型的元框中创建的插件元生成器文件( meta-generator-file.php )
<?php
/**
* Generated by the WordPress Meta Box generator
* at http://jeremyhixon.com/tool/wordpress-meta-box-generator/
*/
function jobs_get_meta( $value ) {
global $post;
$field = get_post_meta( $post->ID, $value, true );
if ( ! empty( $field ) ) {
return is_array( $field ) ? stripslashes_deep( $field ) :
stripslashes( wp_kses_decode_entities( $field ) );
} else {
return false;
}
}
function jobs_add_meta_box() {
add_meta_box(
'jobs-jobs',
__( 'Jobs', 'jobs' ),
'jobs_html',
'post',
'normal',
'default'
);
add_meta_box(
'jobs-jobs',
__( 'Jobs', 'jobs' ),
'jobs_html',
'jobs',
'normal',
'default'
);
}
add_action( 'add_meta_boxes', 'jobs_add_meta_box' );
function jobs_html( $post) {
wp_nonce_field( '_jobs_nonce', 'jobs_nonce' ); ?>
<p>
<label for="jobs_filters"><?php _e( 'Filters', 'jobs' ); ?></label><br>
<select name="jobs_filters" id="jobs_filters">
<option <?php echo (jobs_get_meta( 'jobs_filters' ) === 'All Jobs' )
? 'selected' : '' ?>>All Jobs</option>
<option <?php echo (jobs_get_meta( 'jobs_filters' ) === 'Jobs in
Progress' ) ? 'selected' : '' ?>>Jobs in Progress</option>
<option <?php echo (jobs_get_meta( 'jobs_filters' ) === 'Scheduled
Jobs' ) ? 'selected' : '' ?>>Scheduled Jobs</option>
<option <?php echo (jobs_get_meta( 'jobs_filters' ) === 'Unscheduled
Jobs' ) ? 'selected' : '' ?>>Unscheduled Jobs</option>
</select>
</p>
<p>
<label for="jobs_location"><?php _e( 'Location', 'jobs' ); ?></label>
<br>
<select name="jobs_location" id="jobs_location">
<option <?php echo (jobs_get_meta( 'jobs_location' ) === 'Hyderabad'
) ? 'selected' : '' ?>>Hyderabad</option>
<option <?php echo (jobs_get_meta( 'jobs_location' ) === 'Delhi' ) ?
'selected' : '' ?>>Delhi</option>
<option <?php echo (jobs_get_meta( 'jobs_location' ) === 'Mumbai' )
? 'selected' : '' ?>>Mumbai</option>
<option <?php echo (jobs_get_meta( 'jobs_location' ) === 'Bangalore'
) ? 'selected' : '' ?>>Bangalore</option>
</select>
</p>
<p>
<label for="jobs_designation"><?php _e( 'Designation', 'jobs' ); ?>
</label><br>
<select name="jobs_designation" id="jobs_designation">
<option <?php echo (jobs_get_meta( 'jobs_designation' ) ===
'Designer' ) ? 'selected' : '' ?>>Designer</option>
<option <?php echo (jobs_get_meta( 'jobs_designation' ) ===
'Developer' ) ? 'selected' : '' ?>>Developer</option>
<option <?php echo (jobs_get_meta( 'jobs_designation' ) === 'Team
Lead' ) ? 'selected' : '' ?>>Team Lead</option>
<option <?php echo (jobs_get_meta( 'jobs_designation' ) === 'CEO' )
? 'selected' : '' ?>>CEO</option>
</select>
</p><?php
}
function jobs_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! isset( $_POST['jobs_nonce'] ) || ! wp_verify_nonce(
$_POST['jobs_nonce'], '_jobs_nonce' ) ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
if ( isset( $_POST['jobs_filters'] ) )
update_post_meta( $post_id, 'jobs_filters', esc_attr(
$_POST['jobs_filters'] ) );
if ( isset( $_POST['jobs_location'] ) )
update_post_meta( $post_id, 'jobs_location', esc_attr(
$_POST['jobs_location'] ) );
if ( isset( $_POST['jobs_designation'] ) )
update_post_meta( $post_id, 'jobs_designation', esc_attr(
$_POST['jobs_designation'] ) );
}
add_action( 'save_post', 'jobs_save' );
/*
Usage: jobs_get_meta( 'jobs_filters' )
*/
用于高级内容的单个文件( single-file.php )
<?php get_header(); ?>
<section id="content">
<div class="wrap-content blog-single">
<?php
$mypost = array( 'post_type' => 'd4d_jobs_reviews', );
$loop = new WP_Query( $mypost );
?>
<?php if ($loop->have_posts()) : while ($loop->have_posts()) :
$loop->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title( '<h1>','</h1>' ); ?>
<div class="post-thumbnail">
<?php the_post_thumbnail(array(250, 250)); ?>
</div>
<div class="entry-content">
<?php the_content();
var_dump( 'the_content' ); ?>
</div>
</article>
<?php endwhile; ?>
<?php endif; ?>
</div>
</section>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>
用于链接单个文件和另一个文件的功能文件( functions-file.php )
<?php
/**
* wp_d4d_jobs_Plugin class.
*/
if ( ! class_exists( 'wp_d4d_jobs_Plugin' ) ) {
class wp_d4d_jobs_Plugin {
function atp_constant() {
/**
* framework general variables and directory paths.
*/
$plugin_data = wp_get_plagin();
$pluginversion = $theme_data->Version;
$theme_name = $theme_data->Name;
/**
* Set the file path based on whether the Options
* Framework is in a parent folder of the plugin
* Directory Structure
*/
define( 'PLUGINNAME', $plugin_name );
define( 'PLUGINVERSION', $pluginversion );
define( 'PLUGIN_URI', get_plugin_directory_uri() );
define( 'PLUGIN_DIR', get_template_directory() );
define( 'PLUGIN_JS', PLUGIN_URI . '/js' );
define( 'PLUGINE_CSS', PLUGIN_URI . '/css' );
define( 'ADMIN_URI', FRAMEWORK_URI . 'admin' );
define( 'ADMIN_DIR', FRAMEWORK_DIR . 'admin' );
define( 'PLUGIN_WIDGETS', FRAMEWORK_DIR . 'widgets/') ;
define( 'PLUGIN_CUSTOMMETA', FRAMEWORK_DIR . 'custom-meta/' );
define( 'PLUGIN_PATTDIR', PLUGIN_URI . '/images/patterns/' );
}
function d4d_jobs_function( $plugin_path ) {
if ( get_post_type() == 'd4d_jobs_reviews' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $plugin_file = locate_plugin( array ( 'd4d-
single.php' ) ) ) {
$plugin_path = $plugin_file;
} else {
$plugin_path = plugin_dir_path( __FILE__ ) . '/d4d-
single.php';
}
} else {
if ( $plugin_file = locate_plugin( array (
'category.php' ) ) ) {
$plugin_path = $plugin_file;
} else {
$plugin_path = plugin_dir_path( __FILE__ ) .
'/category.php';
}
}
}
return $plugin_path;
require_once( PLUGIN_DIR . './d4d-single.php' );
}
add_filter( 'plugin_d4d', 'd4d_jobs_function', 1 );
function wp_d4d_jobs_posttype() {
require_once( PLUGIN_DIR . './d4d-jobs.php' );
}
}
add_action( 'calling_class', 'wp_d4d_jobs_Plugin' );
}