WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
Archive Categories with multiple pages (7 posts)

  1. mizujin
    Member
    Posted 4 months ago #

    Hello,

    thanks for this great plugin, it helped us a lot in our Website.

    We are using it mainly in our Archive page. I have about ten categories and only the main category works fine. The main category, "Archives" list all post from all categories, while the other categories are more specific.

    When we choose one of theses other categories and click on page 2, it will go back to the main category.

    You can view the section here. The only other category with more than one page is "Mieux-vivre" at the moment.

    Here is the code from the "Mieux-vivre" template part :

    <!-- MIEUX-VIVRE -->
    
    <?php if(is_page('mieux-vivre')): ?>
        <?php echo "<h1>".$post->ID."</h1>"?>  // Showing post ID for quick identification.
    <?php function my_custom_posts_per_page( $my_query ) {
        if (!is_admin() && post_type_exists('mieux-vivre') )
            $my_query->set( 'posts_per_page', 6 );
        }
    
        add_filter('parse_query', 'my_custom_posts_per_page'); ?>
    
                 <!-- The timeline section let you sort post by year -->
    
                 <div class="timeline">
    				<a href="<?php echo get_permalink(241); ?>"<?php if(empty($dateoti)): ?>class="active"<?php endif; ?>>Tous</a>
    				<?php for($i=2012; $i <= date("Y",time()); $i++){ ?>
    					<a href="<?php echo get_permalink(241); echo "annee/"; echo $i; ?>" <?php if(!empty($dateoti) && $dateoti == $i): ?>class="active"<?php endif; ?>><?php echo $i; ?></a>
    				<?php } ?>
    			</div>
    
    			<span class="band"><?php include('bandeau-archives.php'); ?></span>
    <?php $my_query = new WP_Query( array( 'cat' => '5', 'paged' => get_query_var('paged') ) ); ?>
    <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    
                            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                            	<a href="<?php the_permalink(); ?>">
    								<?php the_post_thumbnail(  array(172,0,true) ); ?>
                                     <h5>
    								 	<?php if (strlen($post->post_title) > 81) {
    									echo substr(the_title($before = '', $after = '', FALSE), 0, 81) . '...'; } else {
    									the_title();
    									} ?>
                                     </h5>
                                     <p><?php
    									$excerpt = get_the_excerpt();
    									echo string_limit_words($excerpt,15);
                                    ?>...</p>
                                     <p class="date"><?php echo get_the_date(); ?> </p>
                                 </a>
                            </div><!-- #post-## -->
    
                    <?php endwhile; ?>
                   <?php wp_pagenavi( array( 'query' => $my_query ) ); wp_reset_postdata(); ?>
                <?php endif; ?>

    The code for the main category is the same except for the cat ID.
    Can you tell me what's going wrong ?

    Thanks !

    https://wordpress.org/plugins/wp-pagenavi/

  2. Lester Chan
    Member
    Plugin Author

    Posted 4 months ago #

    I can't see anything wrong with it,

    Does the default https://codex.wordpress.org/Function_Reference/next_posts_link and https://codex.wordpress.org/Function_Reference/previous_posts_link works in the first place?

  3. mizujin
    Member
    Posted 4 months ago #

    Yes, I already have checked that the default previous/next links worked, The pagenavi prev/next works too.

    Have you checked this link : http://dev.espacehabitat.gouv.qc.ca/archives/mieux-vivre/

    6 post from this category are shown, but when going to page 2, page is changing to main category page 1.

  4. Lester Chan
    Member
    Plugin Author

    Posted 4 months ago #

    Yeap I checked that.

    I can only guess that http://dev.espacehabitat.gouv.qc.ca/archives/mieux-vivre/ is a page and that page doesn't except a /page/ parameter input and hence http://dev.espacehabitat.gouv.qc.ca/archives/mieux-vivre/page/2/ is invalid and it redirect you back to http://dev.espacehabitat.gouv.qc.ca/archives/mieux-vivre/

  5. mizujin
    Member
    Posted 4 months ago #

    Every categories are part of mesarchives.php but are shown conditionnaly with is_page().

    Is it possible with to keep track of the category currently being viewed when changing pages ?

    at the top of page, the categories menu is shown with this :

    <div class="menu_archive">
         <?php wp_nav_menu( array( 'menu_class' => 'archives-menu', 'theme_location' => 'secondary' ) ); ?>
    </div>
  6. Lester Chan
    Member
    Plugin Author

    Posted 4 months ago #

    I guess it should be possible theoretically, by passing the cat_id in the URL, but I guess you have to do your own R&D to find out whether that works.

  7. mizujin
    Member
    Posted 4 months ago #

    It seems like the easiest way for me is not the best but... i'll create separate pages & template for each categories.

    Thanks for your help !

Reply

You must log in to post.

About this Plugin

About this Topic