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.

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

Can only See Source Code in Text Field on Klaviyo
Email Marketing
DTF Digital

Can Only See Source Code In Text Field on Klaviyo

Klaviyo have recently made some UI changes that have been leaving some users a little stumped, mainly what appears to be the removal of the text area editor from the left hand editing pane. Worry not, find out where to locate it in our article.
Read More »
DTF Digital