Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I did a photo gallery with custom post type. The pagination works correct but, if I click to a category, then it must show all photos of the category with pagination, but page 2 not found. You can test it.

http://test.onurunwebsitesi.com

Click to Tümünü Göster (Show All) button, and click to deneme (try) category button and click Daha Eski Fotoğraflar (Previous Photos), there are 3 photos (I didn't add the photos, just added photo titles), I'm listing photos posts_per_page=2, but page 2 not found. Sorry for my bad English. I need your help. I'm working with it for a long time. Thanks in advance. My codes:

archive-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 . "&amp;w=100&amp;h=100&amp;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(); ?> 

functions.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');

?>
share|improve this question
1  
Are you sure this topic hasn't been covered before? wordpress.stackexchange.com/… . . . . . Please, use proper indentation when pasting code, it makes the Question much easier to read. . . . And a suggestion for a debugging method: make a very simple archive-fotograf.php until you know it's working. –  brasofilo Jul 28 '12 at 20:03
    
If you can try wp-pagenavi plugin, you can use Scribu tip for custom queries scribu.net/wordpress/wp-pagenavi/wpn-2-74.html –  Diana Jul 28 '12 at 23:10
    
Thanks for answer, but nothing changed. :( –  onur Jul 29 '12 at 12:14
    
"but nothing changed" doesn't really help... –  kaiser Jul 29 '12 at 12:55
    
@kaiser Hi, can you help me? –  onur Jul 29 '12 at 17:57
show 1 more comment

1 Answer

up vote 1 down vote accepted

I did! My new codes:

<?php /** * Displays the Pagination in Custom loop * */?>
<?php get_header(); ?>
<?php global $wp_query;
$aranan= $_GET['s']; 
$kategorim = intval($_GET['cat']);
$kateg1= $_GET['kategorisec'];
if (intval($kateg1)<0) { $kateg = ""; } else { $kateg = $kateg1; }
$myterm = get_term( $kategorim, 'fgaleri' ); 
global $myslug;
$myslug = $myterm->slug; ?>
<div id="content">
<?php $rakam= 0;
//The query
$wp_query->query( array( 'post_type' =>'fotograf', 's' => $aranan, 'paged' => $paged, 'taxonomy' => 'fgaleri', 'fgaleri' => $kateg ) );
//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( 'walker'=> new SH_Walker_TaxonomyDropdown(), 'class' => 'postform', 'id' => 'kategorisec', 'name' => 'kategorisec', 'value'=>'slug', '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++; ?>
<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() . '/?kategorisec=' . $term->slug . '&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 . "&amp;w=100&amp;h=100&amp;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 ?><?php ?></div><?php get_sidebar(); ?></div><?php get_footer(); ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.