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.

M&S Cyber Attack - Anonymous Hacker
E-commerce
David Pratt

M&S Cyber Attack – How Do I Protect My Ecommerce Website?

In light of the recent cyber attack on Marks & Spencer, ecommerce security has once again been pushed into the spotlight. Here we explore what happened, why it matters, and how ecommerce business owners using Magento, Shopify or WooCommerce can reduce their risk and strengthen defences.
Read More »
Why Is My Website Not Getting Any Sales - Frustrated
E-commerce
Stacey Pratt

Why Is My Website Not Getting Any Sales?

Struggling to convert traffic into customers? From poor user experience to limited payment options and lack of marketing activity, there are many reasons your online store might not be performing. Let’s go over the most common pitfalls that hold eCommerce businesses back, and how to fix them. Whether you’re using Magento, Shopify, or WooCommerce, these insights could be the key to unlocking better sales!
Read More »
eCommerce Checkout Screen
Adobe Commerce
Stacey Pratt

Will New Buy Now Pay Later Rules Affect My Online Shop?

New UK regulations are coming for Buy Now, Pay Later (BNPL) services like Klarna and Clearpay, aiming to protect customers with affordability checks and clearer terms. But what does this mean for your eCommerce store? Find out what’s changing, when it’s happening, and how it may (or may not) affect your online checkout. It’s nothing to panic about, but it’s worth being prepared.
Read More »
DTF Digital