[英]Wordpress: home page navigation screwed
這是我正在談論的網站。 如果滾動,則到達底部時,您會注意到一個鏈接,該鏈接將繼續進行頁面導航(Pagina successiva)。 如果單擊它,您將獲得與主頁中相同的帖子! 它繼續。 如果您訪問website.com/page/6/,您仍然會獲得首頁帖子。
這是index.php。 它出什么問題了? :o
PS: Wordpress最新版本。 沒有子主題。 我創建的自定義圖片:
<?php get_header(); ?>
<?php if (is_home() && !is_paged()) { ?>
<!-- editoriale -->
<div id="editoriale">
<?php $my_query = new WP_Query('cat=10&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="postinfo" style="margin-top:-10px">
di <a href="<?php echo get_option('home'); ?>/author/<?php the_author_meta( user_nicename ); ?>/"><?php the_author(); ?></a> -
pubblicato il <?php the_time('j F Y') ?> -
<?php comments_popup_link('nessun commento »', '1 commento »', '% commenti »'); ?>
<?php edit_post_link('modifica',' - [ ',' ]'); ?>
</div>
<div id="editoriale-cont" class="entry">
<?php the_content(' Leggi il resto »'); ?>
</div>
<div class="postinfo" style="text-align:right;margin-top:10px">
<a href="<?php echo get_option('home'); ?>/categoria/editoriali/">Tutti gli editoriali »</a>
</div>
<?php edit_post_link('Modifica', ' <div class="edit">', '</div>'); ?>
<?php endwhile; ?>
</div>
<!-- fine editoriale -->
<div class="hotnews" id="bombacalendario">
<div style="padding:10px 0 15px 10px">
<?php $my_query = new WP_Query( 'page_id=18570' );
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate2[] = $post->ID;?>
<h3><?php the_title(); ?></h3>
<div><?php the_content(); ?></div>
<?php edit_post_link('Modifica', ' <div class="edit">', '</div>'); ?>
<?php endwhile; ?>
</div>
</div>
<div style="margin-top:12px;padding-bottom:6px" id="cerca" class="hotnews">
<h3>Cerca nel sito</h3><p>
<form action="<?php echo get_option('home'); ?>/" id="searchform" method="get">
<p><input type="text" style="width:135px;margin-right:10px" value="" name="s" id="s"><input type="submit" value="Vai" id="searchsubmit"></p>
</form>
</div>
<div class="fine-blocco"></div>
<?php } ?>
<?php get_sidebar(); ?>
<!-- inizio contenuto -->
<div id="content">
<!-- post del blog -->
<?php query_posts( 'cat=-7' );
if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="postinfo">
di <a href="<?php echo get_option('home'); ?>/author/<?php the_author_meta( user_nicename ); ?>/"><?php the_author(); ?></a> -
pubblicato il <?php the_time('j F Y') ?><?php edit_post_link('modifica',' - [ ',' ]'); ?> -
<?php comments_popup_link('nessun commento »', '1 commento »', '% commenti »'); ?>
</div>
<div class="entry">
<?php the_content('[Continua »]'); ?>
</div>
</div><br style="clear:both">
<!-- fine post -->
<?php endwhile; else: ?>
<p><?php 'Spiacente, nessun risultato.'; ?></p>
<?php endif;?>
<p class="navigation">
<?php posts_nav_link(' - ', '« Pagina Precedente', 'Pagina Successiva »'); ?>
</p>
</div>
<!-- fine contenuto -->
<?php get_footer(); ?>
如您所見,在網站上看到的是,主頁上有一個硬編碼的頁面(應保留在每個下一頁,然后是“精選”的帖子,該帖子不應出現在下一頁)。 問題是,當您轉到第2、3等頁時,一切都被搞砸了:D
分頁不起作用的原因是您沒有向query_posts
函數添加正確的參數。
你有這個: query_posts( 'cat=-7' );
但是您也需要添加paged
參數。 您可能還想添加posts_per_page
請參閱Wordpress編解碼器: http : //codex.wordpress.org/Function_Reference/query_posts#Pagination
另請參閱以獲取分頁參數: http : //codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query
這是一個例子:
$args = array(
'cat' => '-7',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
);
query_posts($args);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.