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.

This question already has an answer here:

I coded a WordPress theme. I added a Photo Gallery with custom post type. But if paged>=2, it gives 404 error.

If you open my web site link and click Tümünü Göster (Show All) button, you can test it.

Codes:

functions.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 ); 
}
function mySearchFilter_0987($query) { 
$post_type = $_GET['post_type']; 
if (!$post_type) { 
$post_type = 'any'; 
} 
if ($query->is_search) { 
$query->set('post_type', $post_type); 
}; 
return $query; 
}; 
add_filter('pre_get_posts','mySearchFilter_0987');

archive-fotograf.php

<?php get_header(); ?>
<?php $aranan= $_GET['s']; ?>
<div id="content">
<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'fotograf' , 's' => $aranan, 'posts_per_page' => 1, 'paged' => $paged ); 
query_posts($args);
if (have_posts()) : $rakam=0; ?><div id="FGaleri"><div id="FGaleri_Ic"><div id="FGaleriBaslik">Fotoğraf Galerisi 
<form action="<?php echo get_bloginfo('wpurl'); ?>" id="searchform" method="get" name="searchform">
<input name="s" id="s" type="text" value=""/>
<input type="hidden" name="post_type" value="fotograf" /> 
<input id="searchsubmit" type="submit" value="Ara"/>
</form>
</div><div class="FGaleri_Ic_2"><?php while( have_posts() ) : the_post(); $rakam++; ?>
<div class="FGaleriItem2" style="<?php if ($rakam % 5 == 0 ) { ?>margin-right: 0px;<?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="clearboth2"></div><?php } ?><?php endwhile; ?></div></div></div><div class="clearboth"></div>
<div id="navigasyon"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?><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><?php } ?></div>
<?php else : ?><p class="bulunamadi">Yazı bulunamadı.</p><?php endif; ?>
</div><?php wp_reset_query(); ?><?php get_sidebar(); ?></div><?php get_footer(); ?>
share|improve this question
add comment

marked as duplicate by toscho Jun 8 '13 at 10:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

If you want to simple alter in the main loop then using pre_get_posts hook will be best. You can find its references in WordPress codex as well. Also here is a post how to make pagination work with your custom loop http://devotepress.com/coding/wordpress-custom-loop-pagination/. hope this helps you

share|improve this answer
    
Thanks for answer. I do changes but nothing changed. Still gives error if paged>=2 :( If you add my MSN, I will send my theme codes. I think you can solve it. –  onur Jul 16 '12 at 18:25
    
Hi, Onur Go to your admin backend and on your reading setting set your blog pages show at most of 1 and just check whether it works or not. Also try to remove any caching if you are using any plugins. –  rabin shrestha Jul 17 '12 at 4:46
add comment

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