name=realestate
嗨,我的英语非常非常糟糕,抱歉:) wordpress 自定义帖子分类已name=realestate_cat
创建。我想创建一个基于分类类别的内容的帖子列表我的代码
<?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
}