自定义投递类型分页404错误(如果分页>=2)

时间:2012-07-16 作者:onur

我编写了一个WordPress主题。我添加了一个带有自定义帖子类型的照片库。但如果paged>=2, 它给出404错误。

如果您打开my web site 链接并单击TümünüGöster(全部显示)按钮,您可以对其进行测试。

代码:

功能。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\');
存档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(); ?>

1 个回复
SO网友:Rabin shrestha

如果您想在主循环中进行简单的更改,那么使用pre\\u get\\u posts挂钩将是最好的选择。你也可以在WordPress codex中找到它的参考文献。这里还有一篇文章,介绍了如何使用自定义循环进行分页http://devotepress.com/coding/wordpress-custom-loop-pagination/. 希望这对你有帮助

结束

相关推荐

Change posts URL

Possible Duplicate:Permalink: postname EXCEPT for blog 我已经同意将我的网站转换为wordpress,并使用了索引。php作为主页和博客。php(博客帖子的模板),但当我创建任何新帖子时,它会生成类似permalink的页面,例如。。。http://www.domain.com/post-name 而不是http://www.domain.com/blog/post-1你能帮助我如何为所有博客帖子分配/写博客吗。谢谢你的帮助。