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 . "&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="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(); ?>