好的,根据您在评论中所写的内容,您希望转到wp-content/plugins/
目录并在其中创建一个新目录。我们称之为:zains-locations.
在该目录中,创建一个名为:zains-locations.php
在该文件中,添加以下内容:
<?php
/*
Plugin Name: Zain\'s Location Taxonomy
Description: Add\'s location taxonomy.
Version: 1.0
Author: zain
Author URI: http://www.yourdomain.com
Text Domain: zain
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
//BLOCK DIRECT ACCESS
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}
function zain_location_taxonomies() {
//Deliverables
$labels = array(
\'name\' => _x( \'Locations\', \'taxonomy general name\', \'zain\' ),
\'singular_name\' => _x( \'Location\', \'taxonomy singular name\', \'zain\' ),
\'search_items\' => __( \'Search Locations\', \'zain\' ),
\'popular_items\' => __( \'Popular Locations\', \'zain\' ),
\'all_items\' => __( \'All Locations\', \'zain\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit Location\', \'zain\' ),
\'update_item\' => __( \'Update Location\', \'zain\' ),
\'add_new_item\' => __( \'Add New Location\', \'zain\' ),
\'new_item_name\' => __( \'New Locations Name\', \'zain\' ),
\'separate_items_with_commas\' => __( \'Separate Locations with commas\', \'zain\' ),
\'add_or_remove_items\' => __( \'Add or remove Location\', \'zain\' ),
\'choose_from_most_used\' => __( \'Choose from the most used locations\', \'zain\' ),
\'not_found\' => __( \'No Locations found.\', \'zain\' ),
\'menu_name\' => __( \'Locations\', \'zain\' ),
);
$args = array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'zain-location\' ),
);
register_taxonomy( \'zain_locations\', \'posts\', $args );
}
add_action( \'init\', \'zain_location_taxonomies\', 0 );
function zain_locations( $post ) {
global $post;
$zain_locations = get_the_terms( $post->ID, \'zain_locations\' );
if ( !empty( $cgport_deliverables ) ) :
$locations_string = join( \', \', wp_list_pluck( $zain_locations, \'name\' ) );
echo \'<div class="zain-locations">\';
echo \'<span class="zain-location">\' . $locations_string . \'</span>\';
echo \'</div>\';
endif;
}
?>
当然,编辑和自定义您需要的内容,比如您在撰写中的域,如果您要继续使用和维护它,您应该编写一个自述。带有变更日志等的md文件。
安装完成后,您必须解决下一个问题,即如何在主题中获得您想要的分类法。在上面的代码中,通过插件,我生成了一个可以使用的模板标记:
<?php zain_locations(); ?>
现在,取决于使用它的位置和方式,例如如果在循环之外,则需要像这样将post ID传递给它
<?php zain_locations( $post->ID ); ?>
, 但是如果在循环中,您可以只使用标记本身。
查看Bimber的文档,模板中似乎没有任何挂钩,您可以使用插件在任何特定点插入模板标记,因此您很可能需要创建一个子主题:http://docs.bimber.bringthepixel.com/articles/your-custom-code/using-the-child-theme/index.html
除此之外,您可能还需要编写一些CSS,以使位置以您希望的方式显示,然后继续细化细节。
希望这有帮助。