2013-09-11 47 views
0

大家好,我的英語非常非常糟糕的遺憾:)WordPress的自定義後name=realestate taxonmy name=realestate_cat created.I要根據分類類別 我的代碼WordPress的分類類別過濾

<?php 
    $args = array(
     'post_type'=> 'realestate', 
     'taxonomy' => 'realestate_cat', 
     'cat' => 2, 
    ); 
    query_posts($args); 
    if (have_posts()) : while (have_posts()) : the_post(); 
    ?> 

此代碼創建的內容的帖子列表不行......


我的功能代碼:

function themes_taxonomy() { 
    register_taxonomy(
     'emlak_kategori', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
     'emlak',   //post type name 
     array(
      'hierarchical'  => true, 
      'label'    => 'Emlak Kategorileri', //Display name 
      'query_var'   => true, 
      'rewrite'   => array(
        'slug'   => 'emlak', // This controls the base slug that will display before each term 
        'with_front' => false // Don't display the category base before 
        ) 
      ) 
     ); 
} 
add_action('init', 'themes_taxonomy'); 
function filter_post_type_link($link, $post) { 
    if ($post->post_type != 'emlak') 
     return $link; 

    if ($cats = get_the_terms($post->ID, 'emlak_kategori')) 
     $link = str_replace('%emlak_kategori%', array_pop($cats)->slug, $link); 
    return $link; 
} 
add_filter('post_type_link', 'filter_post_type_link', 10, 2); 
add_action('init', 'register_themepost', 20); 
function register_themepost() { 
    $labels = array(
     'name' => _x('Emlaklar', 'catchthemes_custom_post','catchthemes'), 
     'singular_name' => _x('Theme', 'catchthemes_custom_post', 'catchthemes'), 
     'add_new' => _x('Emlak Ekle', 'catchthemes_custom_post', 'catchthemes'), 
     'add_new_item' => _x('Yeni Bir Emlak Ekle', 'catchthemes_custom_post', 'catchthemes'), 
     'edit_item' => _x('Emlak İlanını Düzenleyin', 'catchthemes_custom_post', 'catchthemes'), 
     'new_item' => _x('Yeni Emlak İlanı', 'catchthemes_custom_post', 'catchthemes'), 
     'view_item' => _x('Emlak İlanınızı Önizleyin', 'catchthemes_custom_post', 'catchthemes'), 
     'search_items' => _x('Emlak Ara', 'catchthemes_custom_post', 'catchthemes'), 
     'not_found' => _x('Henüz Emlak İlanı Eklenmemiş', 'catchthemes_custom_post', 'catchthemes'), 
     'not_found_in_trash' => _x('Çöp Kutusunda Birşey Bulunamadı', 'catchthemes_custom_post', 'catchthemes'), 
     'parent_item_colon' => _x('Parent ThemePost:', 'catchthemes_custom_post', 'catchthemes'), 
     'menu_name' => _x('Emlaklar', 'catchthemes_custom_post', 'catchthemes'), 
    ); 

    $args = array(
     'labels' => $labels, 
     'hierarchical' => false, 
     'description' => 'Emlaklar', 
     'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields'), 
     'taxonomies' => array('post_tag','emlak_kategori'), 
     'show_ui' => true, 
     'show_in_menu' => true, 
     'menu_position' => 5, 
     'menu_icon' => get_stylesheet_directory_uri() . '/images/maidenstower.png', 
     'show_in_nav_menus' => true, 
     'publicly_queryable' => true, 
     'exclude_from_search' => false, 
     'query_var' => true, 
     'can_export' => true, 
     'rewrite' => array('slug' => 'emlak/%emlak_kategori%','with_front' => FALSE), 
     'public' => true, 
     'has_archive' => 'emlak', 
     'capability_type' => 'post' 
    ); 
    register_post_type('emlak', $args);//max 20 charachter cannot contain capital letters and spaces 
} 
+1

什麼是您的分類項? –

+0

我真的不知道你的水平wp/php ...但是你發佈的特定代碼,如果保持這樣,將不會顯示任何內容。你是否嘗試過例如添加'the_title()'或'echo get_the_ID()'? (對不起,如果我說明明顯......但在SE上你永遠不會知道..) –

回答

0

必須與分類項嘗試像下面

<?php 
    $args = array(
     'post_type'=> 'realestate', 
     'taxonomy' => 'realestate_cat', 
     'term'=>'your taxonomy term' 
     'cat' => 2, 
    ); 
    query_posts($args); 
    if (have_posts()) : while (have_posts()) : the_title(); the_post(); 
    ?> 
相關問題