Wordpress自定义帖子类型未在前端显示自定义类别

时间:2014-09-24 04:56:54

标签: wordpress plugins custom-taxonomy

我的自定义帖子和分类法有些麻烦。当我打电话给 url/team 时,它会显示我的所有自定义帖子,但是当我想要调用类别页面时,例如" labor"比如 url/team/labor ,我得到了404。

以下是我的插件文件中自定义帖子类型和分类的注册:

$labels = array(
    'name'                  => 'Team',
    'singular_name'         => 'Team-Mitglied',
    'add_new'               => 'Neues Team-Mitglied',
    'add_new_item'          => 'Hinzufügen',
    'edit_item'             => 'Team-Mitglied bearbeiten',
    'new_item'              => 'Neues Team-Mitglied',
    'all_items'             => 'Alle Team-Mitglieder',
    'view_item'             => 'Team-Mitglied anzeigen',
    'search_items'          => 'Team-Mitglied suchen',
    'not_found'             => 'Team-Mitglied nicht gefunden',
    'not_found_in_trash'    => 'Team-Mitglied nicht im Papierkorb gefunden',
    'parent_item_colon'     => '',
    'menu_name'             => 'Team',
);

$args = array( 
    'labels'                => $labels,
    'description'           => 'Team-Mitglieder erstellen und verwalten',
    'hierarchical'          => true,        
    'supports'              => array( 'title', 'thumbnail','editor'),
    'public'                => true,
    'show_ui'               => true,
    'menu_position'         => 25,
    'show_in_menu'          => true,       
    'show_in_nav_menus'     => true,
    'publicly_queryable'    => true,
    'exclude_from_search'   => true,
    'has_archive'           => true,
    'query_var'             => true,
    'can_export'            => true,
    'rewrite'               => true,
    'capability_type'       => 'post',
    'menu_icon'             => plugins_url( '../img/icon.png',__FILE__),
    'has_archive'           => true,
    'rewrite'               => array( 'slug' => 'team' )

);

register_post_type( 'team_manager', $args );
flush_rewrite_rules();  // renew the rewrite rules

//register custom category for the team manager
$labels = array(
    'name'                       => 'Abteilungen',
    'singular_name'              => 'Abteilung',
    'search_items'               => 'Abteilung suchen',
    'popular_items'              => 'Beliebteste Abteilungen',
    'all_items'                  => 'Alle Abteilungen',
    'parent_item'                => null,
    'parent_item_colon'          => null,
    'edit_item'                  => 'Abteilung bearbeiten',
    'update_item'                => 'Abteilung aktualisieren',
    'add_new_item'               => 'Neue Abteilung',
    'new_item_name'              => 'Neuer Abteilungsname',
    'separate_items_with_commas' => 'Abteilungen durch Komma trennen',
    'add_or_remove_items'        => 'Abteilungen hinzufügen oder entfernen',
    'choose_from_most_used'      => 'Aus den meist genutzten Abteilungen wählen',
    'not_found'                  => 'Keine Abteilung gefunden',
    'menu_name'                  => 'Abteilungen',
);

$args = array(
    'hierarchical'          => true,
    'labels'                => $labels,
    'show_ui'               => true,
    'show_admin_column'     => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var'             => true,
    'rewrite'               => array( 'slug' => 'abteilungen' )
);

register_taxonomy( 'team_groups', 'team_manager', $args );

这是我的archive-team_manager.php

的一部分
    $the_query = new WP_Query(array(
        'post_type' => 'team_manager',
        'tax_query' => array(
            'taxonomy'  => 'team_groups',
        ),
        'nopaging' => true,
    ));

    if ( $the_query->have_posts() ) : ?>

        <?php
        while ( $the_query->have_posts() ) { ?>
            <div class="team-member">
                <?php $the_query->the_post(); ?>

                <div class="team-member-pic">
                    <?php echo get_the_post_thumbnail( $post_id, 'full', array( 'class' => 'alignleft' ) ); ?>
                </div><!-- END .team-member-pic -->

                <div class="team-member-meta">
                    <?php 
                    $prename = get_post_meta( get_the_ID(), 'td-staff-prename', true );
                    if(! empty($prename)) {
                        echo '<span class="team-member-prename">' . $prename . '</span><br />';
                    }

                    $name = get_post_meta( get_the_ID(), 'td-staff-name', true );
                    if(! empty($name)) {
                        echo '<span class="team-member-name">' . $name . '</span>';
                    }

                    $td_staff_function = get_post_meta( get_the_ID(), 'td-staff-function', true );
                    if(! empty($td_staff_function)) {
                        echo '<p class="team-member-function">' . $td_staff_function . '</p>';
                    }?>
                </div><!-- END .team-member-meta -->

                <div class="team-member-desc">
                        <?php 
                        $td_staff_job_training = get_post_meta( get_the_ID(), 'td-staff-job-training', true );
                        if(! empty($td_staff_job_training)) {
                            echo "<p><strong>Berufsausbildung:</strong> " . $td_staff_job_training . "</p>";
                        }?>

                        <?php 
                        $td_staff_service_area = get_post_meta( get_the_ID(), 'td-staff-service-area', true );
                        if(! empty($td_staff_service_area)) {
                            echo "<p><strong>Arbeitsbereich:</strong> " . $td_staff_service_area . "</p>";
                        }?>

                        <?php 
                        $td_staff_employment_since = get_post_meta( get_the_ID(), 'td-staff-employment-since', true );
                        if(! empty($td_staff_employment_since)) {
                            echo "<p><strong>Beschäftigt seit:</strong> " . $td_staff_employment_since . "</p>";
                        }?>

                        <?php 
                        $td_staff_birthday = get_post_meta( get_the_ID(), 'td-staff-birthday', true );
                        if(! empty($td_staff_birthday)) {
                            echo "<p><strong>Geburtsdatum:</strong> " . $td_staff_birthday . "</p>";
                        }?>
                </div><!-- END .team-member-desc -->
            </div><!-- END .team-member -->
        <?php   
        }

    else :
        get_template_part( '/partials/content', 'not-found' );
    endif;

我用taxonomy.php尝试过,但这并没有奏效。我读了所有关于这个的wordpress-codex,但我真的很想知道它为什么不起作用!我需要一个自定义类别档案的网址结构,如下所示:

`url / team`(来自我的自定义帖子类型的所有帖子)*已完成*
`url / team / labor`(我的自定义帖子中的所有帖子都输入了特定的自定义类别)* 404错误*

最后,我希望你们对我有一点线索:)

1 个答案:

答案 0 :(得分:0)

试试这个

$terms = get_terms( 'your_own_taxonomy_name', array(
                    'orderby'    => 'count',
                    'hide_empty' => 0,
                  ) );

foreach( $terms as $term ) {
       $args = array(
                     'post_type' => 'your_own_post_type_name',
                     'order' => 'DESC'
                    );
       $query = new WP_Query( $args ); 
       echo $term->name;
      }