我正在使用自定义帖子类型。我想在wp\\U查询循环中显示每个帖子在归档页面上的最子类别。但是\\u类别(“”);不起作用。我该怎么办?我需要你的帮助。对不起,我的英语不好。提前谢谢。
我的代码:
存档fotograf。php
<?php
/**
* Displays the Pagination in Custom loop
*
*/
?>
<?php get_header(); ?>
<?php $aranan= $_GET[\'s\'];
$kategorim = intval($_GET[\'cat\']);
$myterm = get_term( $kategorim, \'fgaleri\' );
$myslug = $myterm->slug;
?>
<div id="content">
<?php
$temp = $wp_query; //save old query
$wp_query= null; //clear $wp_query
$rakam= 0;
//The query
$wp_query = new WP_Query();
$wp_query->query( array( \'post_type\' =>\'fotograf\', \'s\' => $aranan, \'paged\' => $paged, \'taxonomy\' => \'fgaleri\', \'fgaleri\' => $myslug ) );
//The loop
?>
<div id="FGaleri_2"><div id="FGaleri_Ic"><div id="FGaleriBaslik">Fotoğraf Galerisi
<form action="<?php echo get_bloginfo(\'wpurl\'); ?>" id="searchformfoto" method="get" name="searchform">
<?php
$args = array(
\'taxonomy\' => \'fgaleri\',
\'show_option_none\' => false,
\'hierarchical\' => 1
);
wp_dropdown_categories($args);
?>
<div id="aramabolumufoto"><input name="s" id="sfoto" type="text" value=""/>
<input type="hidden" name="post_type" value="fotograf" />
<input type="hidden" name="fgaleri" value="<?php echo $myslug; ?>" />
<input id="searchsubmitfoto" type="submit" value="Ara"/></div>
</form>
</div><div class="FGaleri_Ic_2">
<?php while ($wp_query->have_posts()): $wp_query->the_post();
$rakam++;
?>
<div class="FGaleriItem2" style="<?php if ($rakam % 5 == 0 ) { ?>margin-right: 0px;<?php } ?>">
<?php // the_category(\'\'); IS NOT WORKING. I WANT TO POST CATEGORY COME HERE!
?>
<div class="ResimUst"><?php if (has_post_thumbnail()) { ?><a href="<?php the_permalink() ?>"><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );$url2 = get_bloginfo(\'template_directory\') . "/timthumb.php?src=" . $url . "&w=100&h=100&zc=1"; ?><img src="<?php if(get_option(\'of_timthumb\')=="true") { echo $url2; } else { echo $url; } ?>" alt="" title="" width="100" height="100" /></a><?php } ?></div><div class="ResimAlt"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php
?>
</div></div><?php endwhile; ?></div></div></div><div class="clearboth"></div>
<?php if(function_exists(\'wp_pagenavi\') ) {
wp_pagenavi(); //function call for plugin pagination( wp pagenavi plugin)
}else{ ?>
<div id="navigasyon">
<span class="previous-entries"><?php next_posts_link(\'« Daha Eski Fotoğraflar\'); ?></span>
<span class="next-entries"><?php previous_posts_link(\'Daha Yeni Fotoğraflar »\'); ?></span>
</div>
<?php
}//endif
?>
<?php
wp_reset_postdata();
$wp_query = null; //Reset the normal query
$wp_query = $temp;//Restore the query
?>
</div><?php get_sidebar(); ?></div><?php get_footer(); ?>
功能。php
<?php
add_action( \'init\', \'register_cpt_fotograf\' );
function register_cpt_fotograf() {
$labels = array(
\'name\' => _x( \'Fotoğraflar\', \'fotograf\' ),
\'singular_name\' => _x( \'Fotoğraf\', \'fotograf\' ),
\'add_new\' => _x( \'Yeni Ekle\', \'fotograf\' ),
\'add_new_item\' => _x( \'Yeni Fotoğraf Ekle\', \'fotograf\' ),
\'edit_item\' => _x( \'Fotoğrafı Düzenle\', \'fotograf\' ),
\'new_item\' => _x( \'Yeni Fotoğraf\', \'fotograf\' ),
\'view_item\' => _x( \'Fotoğrafı Önizle\', \'fotograf\' ),
\'search_items\' => _x( \'Fotoğraf Ara\', \'fotograf\' ),
\'not_found\' => _x( \'Fotoğraf Bulunamadı\', \'fotograf\' ),
\'not_found_in_trash\' => _x( \'Çöpte Fotoğraf Bulunamadı\', \'fotograf\' ),
\'parent_item_colon\' => _x( \'Ana Fotoğraf:\', \'fotograf\' ),
\'menu_name\' => _x( \'Fotoğraflar\', \'fotograf\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => false,
\'supports\' => array( \'title\', \'author\', \'thumbnail\', \'custom-fields\', \'comments\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => false,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => array(\'slug\' => \'fotograflar\'),
\'capability_type\' => \'post\'
);
register_post_type( \'fotograf\', $args );
}
register_taxonomy("fgaleri", "fotograf", array("hierarchical" => true, "label" => "Fotoğraf Kategorileri", "singular_label" => "Fotoğraf Kategorisi", \'show_ui\' => true, \'show_tagcloud\' => false, "rewrite" => array(\'slug\'=>\'fkat\')));
function mySearchFilter_0987($query) {
$post_type = $_GET[\'post_type\'];
if (!$post_type) {
$post_type = \'post\';
}
$query->set(\'post_type\', $post_type);
return $query;
};
add_filter(\'pre_get_posts\',\'mySearchFilter_0987\');
// This filter will jump into the loop and arrange our results before they\'re returned
function limit_posts_per_archive_page() {
if (is_post_type_archive()) { $limit = 20; } else { $limit = get_option(\'posts_per_page\'); }
set_query_var(\'posts_per_archive_page\', $limit);
}
add_filter(\'pre_get_posts\', \'limit_posts_per_archive_page\');
if (!term_exists( \'Fotoğraf Galerisi\', \'fgaleri\') ) {
wp_insert_term( \'Fotoğraf Galerisi\', \'fgaleri\',
array( \'description\' => \'Fotoğraf Galerisi\', \'slug\' => \'fotogaleri\' ) );
}
add_filter( \'request\', \'my_request_filter\' );
function my_request_filter( $query_vars ) {
if( isset( $_GET[\'s\'] ) && empty( $_GET[\'s\'] ) ) {
$query_vars[\'s\'] = " ";
}
return $query_vars;
}
?>