• Hello,

    I’ve set up a page page-stream.php which displays all “posts” ever made from all custom post types arranged by month.

    It sort of works, but only if you set it to display all which is not ideal considering we have tens of thousands of posts.

    Now, at the moment, I’ve set posts per page to 100, however pagination does not appear. How would I go about fixing this.

    Below is functions.php function for the timeline

    function timeline_month() {
       $months = array();
    	$posts = get_posts(array(
        'showposts' => 100,
        'orderby' => 'post_date',
        'order' => 'DESC',
    	'paged' => $paged,
        'post_type' => array('post', 'audio', 'releases', 'videos', 'events', 'merchandise'),
         ));
      foreach($posts as $post) {
      $months[date('F Y', strtotime($post->post_date))][] = $post;
      }
    
      return $months;
    }

    and below is the entire page-stream.php

    <?php
    /*
    Template Name: stream
    */
    ?>
    <?php get_header(); ?>
    </div>
    <div class="pagetitle">
    <h1>Grime Forum Time Line</h1>
    </div>
    
    <div class="timelinewrap">
    
    <?php foreach(timeline_month() as $months => $posts) : ?>
    <div class="timeline-month"><?php echo $months; ?></div>
    
    <?php foreach($posts as $post) : setup_postdata($post); ?>
    
    <div class="timelinepost">
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
    
    <?php endforeach; ?>
    
    <?php endforeach; ?>
    
    </div>
    
    <?php if(function_exists('wp_paginate')) {
        wp_paginate();
    } ?>
    
    <div>
    <?php get_footer(); ?>

    and heres link to the page https://www.grimeforum.com/timeline

Viewing 3 replies - 1 through 3 (of 3 total)
  • Two points:
    1 – in your timeline_month function, you pass $paged variable that is not set.
    you can try something like that:

    function timeline_month() {
       $months = array();
    // set the $paged variable and assign value to it
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
       $posts = get_posts(array(
        'showposts' => 100,
        'orderby' => 'post_date',
        'order' => 'DESC',
    	'paged' => $paged,
        'post_type' => array('post', 'audio', 'releases', 'videos', 'events', 'merchandise'),
         ));
      foreach($posts as $post) {
      $months[date('F Y', strtotime($post->post_date))][] = $post;
      }
    
      return $months;
    }

    Please see here for more information.

    2 – wp_paginate is a function provided by the WP-Paginate plugin. Is it installed and active?
    See here for more info on how to use it.

    Thread Starter James Morton

    (@stylishjm)

    Hello, many thanks for the help.
    What I’m trying to aim for is to get some form of “infinite scrolling”, however all of the solutions I have tried (wp infinite scroll, jetpack etc.) have not worked. Could it be because the loop is not directly on the page but in functions.php?

    You may want to try the Infinite-Scroll plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination not working/displaying’ is closed to new replies.