A
A
Alexander Bizikov2014-12-31 11:17:33
WordPress
Alexander Bizikov, 2014-12-31 11:17:33

Taxonomy in Wordpress?

Hello.
Created a new post type "Applications", added taxonomies to it: "Category", "Device", "Platform".
Connecting a new record type:

add_action('init', 'app_init');
    function app_init() {

            // описываем наш тип контента
            $args = array(
                    'label' => __('Приложение'),
                    'labels' => array(
                            'edit_item' => __('Редактировать приложение'),
                            'add_new_item' => __('Нобавить новое приложение'),
                            'view_item' => __('Просмотр'),
                    ),
                    'singular_label' => __('app'),
                    'public' => true,
                    'show_ui' => true,
                    '_builtin' => false,
                    '_edit_link' => 'post.php?post=%d',
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'supports' => array('title', 'editor', 'thumbnail')
            );

            // регистрируем новый тип
            register_post_type( 'app' , $args );

I added taxonomies like this:
register_taxonomy( 'category', 'app',
                    array ('hierarchical' => true, 'label' => __('Категория'),
                            'singular_label' => __('category'),
                            'query_var' => 'category')
            );
register_taxonomy( 'device', 'app',
                    array ('hierarchical' => true, 'label' => __('Устройство'),
                            'singular_label' => __('device'),
                            'query_var' => 'device')
            );
      
register_taxonomy('platform','app',
                    array ('hierarchical' => true, 'label' => __('Платформа'),
                            'singular_label' => __('platform'),
                            'query_var' => 'platform')
            );

How do I do:
  1. Displaying a list of records of a new type;
  2. Data output (category, device, platform) on the record page.

ps. Happy New Year!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mirusck, 2014-01-04
@bizikov

Maybe late, but still:
1. All your posts with the new post type will be displayed on the page yourdomain.com/?post_type=app
If you want a prettier url, add the following arguments when registering the post type:

$args = array(
        ....
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'apps',
            'with_front' => false
        )
}

Then the url will be like this: yourdomain.com/apps .
// If it didn't work, then you need to regenerate the permalinks on the Settings --> Permalinks page
2. Duplicate the archive.php and single.php files in the theme folder into files with the names archive-app.php single- app.php respectively. Now, when displaying your custom posts, these template files will be used. Use the the_terms() or get_the_terms()
function in templates to display category, device and platform . For example:
<?php the_terms($post->ID, 'device'); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question