Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I coded a WordPress theme. I added a Photo Gallery with custom post type. But if paged>=2, it gives 404 error. I'm gonna be mad. :( Help please. And sorry for my bad English. Add me on MSN. onur89@live.com

My web site address: http://www.onurunwebsitesi.com/

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
possible duplicate of Pagination not working with custom loop – Chip Bennett Jan 23 at 20:35

2 Answers

get_query_var('paged') should be get_query_var('page').

From WP_Query:

Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since Wordpress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same.

share|improve this answer
Very thanks for answer. I changed my code. $paged = (get_query_var('page')) ? get_query_var('page') : 1; But same. I dont understand last 3 rows in your message. What should I do? – onur Jul 16 '12 at 15:07
what happens if you remove your call to query_posts? I'm not sure why that's even there or why you're setting the s search query var? – Milo Jul 16 '12 at 15:13
I am using custom post type (named fotograf). And if I delete query_posts, it will show all photos in one page. I want a pagination. And if I delete s query, then search results not working in photo gallery. – onur Jul 16 '12 at 15:23
If you're calling query_posts to simply set posts_per_page, you should use the pre_get_posts filter you already have set up to do that. there's no reason to ever use query_posts in the template. – Milo Jul 16 '12 at 15:28
I don't know it really... Can you write it for me? Thanks. – onur Jul 16 '12 at 15:35
show 1 more comment

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

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.