Reputation: 376
I am using the following code to select and set context for a category landing page on my client's website.
Code
$args = array(
'cat' => '5,3,4,6',
'numberposts' => 5,
'orderby' => 'date',
'order' => 'DESC',
);
$context['stories'] = Timber::get_posts( $args );
I am using this code to set the template and assign context.
Code
if( $category->parent == 0 ) {
// Stories parent category
$templates = array( 'category.twig' );
$context['categories'] = $categories;
}
This is all working, but I am needing to duplicate the functionality and make the following adjustments.
numberofposts
to AllThis layout will act like an "all posts" page. This page will be assigned to a menu item called "All Stories".
Is it possible to make this work without having to write lots of additional code? I am learning Timber and Twig as I go, so please feel free to share some tips and tricks for improving my approach.
Upvotes: 0
Views: 334
Reputation: 1136
Set numberofposts to all.
'numberposts' => -1,
Update context toadd headings.
$context['title'] = single_cat_title( '', false );
$context['description'] = category_description();
Display all of the posts assigned to each category.
$cat_id = 1;
$context['category_posts'] = Timber::get_posts(
array(
'cat' => $cat_id,
'posts_per_page' => -1
)
);
Upvotes: 1