We’ve worked with Fishpig’s WordPress extension on plenty of Magento 1 projects, but unfortunately when we moved over to Magento 2 we found the documentation to be lacking.

Here is a quick tutorial on how to implement some basic filtering. In this particular example, we were looking to show only “post” taxonomies, set the page size to 3, then set the current page to 1 so that we could load up just the 3 most recent posts for a block on our clients homepage.

To start with we created a block to appear within the CMS, set it to use Fishpigs “ListPost” class, and then to select our own template so that we could make the appropriate post modifications

{{block class=”FishPig\WordPress\Block\Post\ListPost” name=”wp.post.list” template=”post/dtflist.phtml”}}

We then created our new template file “dtflist.phtml” within: app/design/frontend/Namespace/Theme/FishPig_WordPress/templates/post/ and copied over the default list.phtml template from the FishPig extension.

After examination of the ListPost class and those higher up the inheritance, we were able to find some of the class methods that we could filter by, and then make adjustments to suit our project.

Our dtflist.phtml file starts with the usual $posts = $this->getPosts();, we then expand upon this with the following:

$posts->setPageSize(3); //set the number of items per page.
$posts->setOrderByPostDate(); //orders our posts by the post date (latest first)
$posts->addPostTypeFilter(“post”); //filters the taxonomy to only show “posts” – otherwise pages and other custom taxonomy can also appear.
$posts->addIsPublishedFilter(); //only show published posts
$posts->setCurPage(1); //set the current page
$posts->load(); //reload the posts based on our filter.
$posts->clear();

The rest of our dtflist.phtml file works as normal with a foreach loop over the $posts object.

Ecommerce Shipping Strategies - Website Options
E-commerce
David Pratt

Ecommerce Shipping Strategies

Ecommerce Shipping Strategies are an important thing to consider when running an ecommerce business. It can mean the difference between a conversion and an abandoned basket.
Read More »
E-commerce
DTF Digital

Temu eCommerce

Temu eCommerce has seen rapid growth recently, but will it fly or fail? Will the temptation of low cost goods direct from the manufacturer in China win over ethical considerations of low cost labour and carbon footprint?
Read More »
DTF Digital