Как я могу создать шаблон архива для таксономии, который отображает термины таксономии в плагине - PullRequest
0 голосов
/ 09 апреля 2020

У меня есть таксономия, создаваемая моим плагином prop_cities, и у него есть правка, которая заставляет его отображаться как example.com/cities/city-term. Я хочу добавить шаблон в example.com/cities/, который будет архивом всех городских терминов, но я не могу заставить его работать. Вот мой полный файл таксономии. php и часть этого файла, которая создает таксономию: https://pastebin.com/9QbKBBj3

class rentPress_Posts_Taxonomy_Taxonomies
{

    public function create()
    {
        add_action( 'init', [ $this, 'propertyAndFloorPlanAssociation' ], 0 );
        add_action( 'init', [ $this, 'propertyTags' ], 0); 
        add_action( 'init', [ $this, 'propertyPets' ], 0);
        add_action( 'init', [ $this, 'propertyAmenities'], 0 );
        add_action( 'init', [ $this, 'propertyCities'], 0 );
    }

    /**
     * Initialize Property Taxonomy
     * Needs To Be Deleted 
     */
    public function propertyAndFloorPlanAssociation() {
        $args = $this->buildArgs('Property', 'Properties');

        // Don't show this on front end
        $args = array_merge(
            $args,
            [
                'hierarchical'               => false,
                'public'                     => false,
                'show_ui'                    => false,
                'show_admin_column'          => false,
                'show_in_nav_menus'          => false,
                'show_tagcloud'              => false
            ]
        );

        register_taxonomy( 'property_relationship', array( RENTPRESS_FLOORPLANS_CPT ), $args );
    }

    /**
     * Initialize Property Tags Taxonomy
     */
    public function propertyTags() {
        $args = $this->buildArgs('Tag', 'Tags');
        register_taxonomy( 'prop_tags', array( RENTPRESS_PROPERTIES_CPT ), $args );
    }

    /**
     * Initialize Property Pets Taxonomy
     */
    public function propertyPets() {
        $args = $this->buildArgs('Pet', 'Pets');
        register_taxonomy( 'prop_pet_restrictions', array( RENTPRESS_PROPERTIES_CPT ), $args );
    }

     /**
     * Initialize Property Amenities Taxonomy
     */
    public function propertyAmenities() {
        $args = $this->buildArgs('Amenity', 'Amenities');
        register_taxonomy( 'prop_amenities', array( RENTPRESS_PROPERTIES_CPT ), $args );   
    }

     /**
     * Initialize Property and Neighborhood City Taxonomy
     */
    public function propertyCities() {
        $args = $this->buildArgs('City', 'Cities');
        register_taxonomy( 'prop_city', array( RENTPRESS_PROPERTIES_CPT, RENTPRESS_NEIGHBORHOODS_CPT ), $args );
    }


    public function taxonomyLabels($singular, $plural)
    {
        $singular = ucwords($singular);
        $plural = ucwords($plural);
        return [
            'name'                       => _x( $plural, 'Taxonomy General Name', RENTPRESS_LANG_KEY ),
            'singular_name'              => _x( "$singular Association", 'Taxonomy Singular Name', RENTPRESS_LANG_KEY ),
            'menu_name'                  => __( $plural, RENTPRESS_LANG_KEY ),
            'all_items'                  => __( "All $plural", RENTPRESS_LANG_KEY ),
            'parent_item'                => __( "Parent $plural", RENTPRESS_LANG_KEY ),
            'parent_item_colon'          => __( "Parent $plural:", RENTPRESS_LANG_KEY ),
            'new_item_name'              => __( "New $singular Name", RENTPRESS_LANG_KEY ),
            'add_new_item'               => __( "Add New $singular", RENTPRESS_LANG_KEY ),
            "edit_item"                  => __( "Edit $singular", RENTPRESS_LANG_KEY ),
            "update_item"                => __( "Update $singular", RENTPRESS_LANG_KEY ),
            "view_item"                  => __( "View $singular", RENTPRESS_LANG_KEY ),
            "separate_items_with_commas" => __( "Separate $plural with commas", RENTPRESS_LANG_KEY ),
            "add_or_remove_items"        => __( "Add or remove $plural", RENTPRESS_LANG_KEY ),
            "choose_from_most_used"      => __( "Choose from the most used", RENTPRESS_LANG_KEY ),
            "popular_items"              => __( "Popular $plural", RENTPRESS_LANG_KEY ),
            "search_items"               => __( "Search $plural", RENTPRESS_LANG_KEY ),
            "not_found"                  => __( "Not Found", RENTPRESS_LANG_KEY ),
        ];
    }

    public function buildArgs($singular, $plural, $args = []) {
        $labels = $this->taxonomyLabels($singular, $plural);
        return array_merge([
            'labels'                     => $labels,
            'hierarchical'               => true,
            'public'                     => true,
            'show_ui'                    => true,
            'show_admin_column'          => true,
            'show_in_nav_menus'          => true,
            'show_tagcloud'              => true,
            'rewrite'                    => array('slug' => strtolower( $plural ), 'with_front' => false)
        ], $args);
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...