0
votes

I recently implemented a blog that takes content from two post types and displays them in a tabbed navigation. The problem I encounter is that I can't seem to be able to create pagination links for each post type without one overriding the other.

<div id="view1">
  {% block content %} {% for post in posts %} {% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %} {% endfor %} {% endblock %}
  <div class="tool-pagination">
    <ul class="pages">
      <li>
        {% if pagination.prev %}
        <a href="{{pagination.prev.link}}" class="prev {{pagination.prev.link|length ? '' : 'invisible'}}">Prev</a>
        {% endif %}
      </li>
      {% for page in pagination.pages %}
      <li>
        {% if page.link %}
        <a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
        {% else %}
        <span class="{{page.class}}">{{page.title}}</span>
        {% endif %}
      </li>
      {% endfor %}
      <li><a href="{{pagination.next.link}}" class="next {{pagination.next.link|length ? '' : 'invisible'}}">Next</a>
      </li>
    </ul>
    {% if pagination.next %} {% endif %}
  </div>
</div>

<!-- Workbench  Tab -->
<div id="view2">
  {% block workbench %} {% for post in workbench %} {% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %} {% endfor %} {% endblock %}
  <div class="tool-pagination">
    <ul class="pages">
      <li>
        {% if pagination.prev %}
        <a href="{{pagination.prev.link}}" class="prev {{pagination.prev.link|length ? '' : 'invisible'}}">Prev</a>
        {% endif %}
      </li>
      {% for page in pagination.pages %}
      <li>
        {% if page.link %}
        <a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
        {% else %}
        <span class="{{page.class}}">{{page.title}}</span>
        {% endif %}
      </li>
      {% endfor %}
      <li><a href="{{pagination.next.link}}" class="next {{pagination.next.link|length ? '' : 'invisible'}}">Next</a>
      </li>
    </ul>
    {% if pagination.next %} {% endif %}
  </div>
</div>

My index.php file looks like this:

$context['pagination'] = Timber::get_pagination();

I tried following the instructions on the timber site pagination but all I've managed to do is choose which category is paginated not both

Thanks in advance!! Ivan

1

1 Answers

1
votes

Multiple pagination wasn't something I really anticipated for. But here's how I think it could work:

$context['posts'] = Timber::get_posts();
$context['posts_pagination'] = Timber::get_pagination();

$query = array('post_type' => 'workbench');
$context['workbench'] = Timber::get_posts($query);
query_posts($query); //this forces WP to rerun query stuff
$context['workbench_pagination'] = Timber::get_pagination();

This is not tested, but based on what you got, this is the closest stab I can take