Domanda

Sto riscontrando alcuni problemi con un sito che sto costruendo, sulla pagina di notizie ha 1 post in primo piano dalla categoria di notizie e poi sotto quella categoria di notizie, ma perdendo la notizia in primo piano perché non voglio quell'articolo ripetutamente.

Per esempio

Pagina 1

  • Post in primo piano - Post 1
  • Post 2
  • Post 3
  • Post 4
  • Post 5

pagina 2

  • Post 6
  • Post 7
  • Post 8
  • Post 9

e così via...

Finora ho avuto alcuni problemi diversi creati da diversi metodi per risolvere il problema. Ho avuto l'ultimo post da pagina 1 che si ripete a pagina 2, ho avuto una pausa di paginazione, pensando a pagina 1 che ha 3 pagine e poi su ogni pagina dopo che dice che ci sono 5 pagine e poi diventa disordinato da lì.

Questo è il codice che ho attualmente, non funziona se qualcuno può aiutarmi in questo sarebbe fantastico. Fondamentalmente ciò di cui ho bisogno è il mio elenco di categorie di notizie che ha ad esempio 5 post nella prima pagina con uno di quei post in primo piano (e in una riga separata dal resto dei post, sono contenuti in una riga) e tutte le altre pagine Avere 4 post e per tutto per paginare correttamente e non avere post duplicati.

Spero che sia abbastanza per andare avanti.

(I numeri per i post per pagina nel blocco di codice sono solo per scopi di test, non ho voglia di fare molti post di prova)

<?php get_header(); ?>

<?php global $wp_query;  

$total_pages = $wp_query->max_num_pages;  

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

?>


    <?php if(is_paged()) : ?>
        <section class="content">

            <div class="news-list">
            <div class="row">

            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>

                <article class="col span_6 news-item">
                    <?php the_post_thumbnail(); ?>
                    <h3><?php the_title(); ?></h3>
                    <p><?php echo limit_words(get_the_excerpt(), '25'); ?>...</p>
                    <p class="date"><?php echo get_the_date(); ?></p>
                    <span class="readmore"><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'block_link', true); ?>Full story</a> »</span>
                </article>


            <?php endwhile; 
                if ($total_pages > 1){  

                $current_page = max(1, get_query_var('paged'));  

                echo '<div class="page_nav">'; 

                echo paginate_links(array(  
                  'base' => get_pagenum_link(1) . '%_%',  
                  'format' => 'page/%#%',  
                  'current' => $current_page,  
                  'total' => $total_pages,  
                ));  

                echo '</div>'; 

                }  ?>
            <?php endif; ?>

            </div>
            </div>

        </section>


    <?php else : ?>

        <section class="content">

            <?php query_posts('showposts=1'); ?>

            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>

                <section class="feature-post">
                <div class="row">

                    <div class="col span_6">
                        <?php the_post_thumbnail(); ?>
                    </div>
                    <div class="col span_3">
                        <h3><?php the_title(); ?></h3>
                        <p><?php echo limit_words(get_the_excerpt(), '25'); ?>...</p>
                        <p class="date"><?php echo get_the_date(); ?></p>
                        <span class="readmore"><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'block_link', true); ?>Full story</a> »</span>
                    </div>
                    <div class="col span_3">

                    </div>

                </div>
                </section>


            <?php endwhile; ?>

            <?php endif; wp_reset_query(); ?>

        </section>

        <div class="news-list">
            <div class="row">
            <?php global $query_string; ?> 
            <?php query_posts( $query_string . '&offset=1' ); ?>
            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>

                <article class="col span_6 news-item">
                    <?php the_post_thumbnail(); ?>
                    <h3><?php the_title(); ?></h3>
                    <p><?php echo limit_words(get_the_excerpt(), '25'); ?>...</p>
                    <p class="date"><?php echo get_the_date(); ?></p>
                    <span class="readmore"><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'block_link', true); ?>Full story</a> »</span>
                </article>


            <?php endwhile; 
                if ($total_pages > 1){  

                $current_page = max(1, get_query_var('paged'));  

                echo '<div class="page_nav">'; 

                echo paginate_links(array(  
                  'base' => get_pagenum_link(1) . '%_%',  
                  'format' => 'page/%#%',  
                  'current' => $current_page,  
                  'total' => $total_pages,  
                ));  

                echo '</div>'; 

                }  ?>
            <?php endif; ?>

            </div>
            </div>

    <?php endif; ?>

<?php get_footer(); ?>

Ottengo quanto segue usando questo codice

Pagina 1

  • Post in primo piano - Post 1
  • Post 2
  • Post 3
  • Post 4
  • Post 5

pagina 2

  • Post 5
  • Post 6
  • Post 7
  • Post 8

Pagina 3

  • Post 9
  • Post 10

... e così via, dopo pagina 2, la paginazione funziona correttamente e non ci sono post ripetuti: S

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top