我做了一个自定义帖子类型的照片库。分页是正确的,但如果我单击某个类别,它必须显示该类别的所有照片,但找不到第2页。您可以测试它。
http://test.onurunwebsitesi.com
单击to TümünüGöster(Show All)按钮,单击to deneme(try)category按钮,单击Daha Eski Fotoğraflar(以前的照片),共有3张照片(我没有添加照片,只是添加了照片标题),我列出了每页2张照片的帖子,但找不到第2页。对不起,我的英语不好。我需要你的帮助。我和它合作了很长时间。提前谢谢。我的代码:
存档fotograf。php
<?php /** * Displays the Pagination in Custom loop * */?>
<?php get_header(); ?>
<?php $aranan= $_GET[\'s\'];
$kategorim = get_query_var(\'cat\');
$catName = strtolower(get_cat_name($kategorim));
$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;
$wp_query = new WP_Query();
//The query
global $query_string;
parse_str( $query_string, $my_query_array );
$paged = ( isset( $my_query_array[\'paged\'] ) && !empty( $my_query_array[\'paged\'] ) ) ? $my_query_array[\'paged\'] : 1;
$wp_query->query(\'posts_per_page=2&post_type=fotograf&s=\' . $aranan . \'&paged=\' . $paged . \'&taxonomy=fgaleri&fgaleri=\' . $myslug );
?>
<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\' => \'Kategori Seç ve Ara\', \'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 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++;
//The loop
?>
<div class="FGaleriItem2" style="<?php if ($rakam % 5 == 0 ) { ?>margin-right: 2px;<?php } ?>">
<?php
$termargs=array(\'orderby\' => \'count\', \'order\' => \'desc\');
$terms = wp_get_post_terms( $post->ID , \'fgaleri\', $termargs );
$t = count($terms);
if ($t>0) { ?>
<div class="fkategori">
<?php $c = 0;
foreach($terms as $term) {
$c++;
if ($c==$t)
{
echo \'<a class="foto_kategori" href="\'. home_url() . \'/?cat=\' . $term->term_id . \'&s=\' . $query_vars[\'s\'] . \'&post_type=fotograf" title="\' . $term->name . \'" \' . \'>\' . $term->name.\'</a> \';
}
} ?>
</div>
<?php } ?>
<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>
</div>
</div>
<?php if (($rakam % 5 == 0 ) && ($rakam > 4)) { ?><div class="clearboth"></div><?php } ?>
<?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
$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\')));
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;
}
function limit_posts_per_archive_page() {
if (is_post_type_archive()) { $limit = 2; } 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\');
?>