Closed kiazhi closed 7 years ago
PROBLEM STATEMENT Created a Page in Magento and added the following code into the content and the page listed the numberings but no content.
{{block class="FishPig\WordPress\Block\Post\ListPost" name="wp.post.list" template="post/list.phtml"}}
I too ran into this issue. Here is what I had to do to get this working:
PLATFORM Magento 2.1.5 Wordpress 4.7.4 PHP 7.0.15
EXTENSION FishPig WordPress Integration 1.0.0.55
ISSUE
post/list.phtml calls incorrect functions for $post->
. This means that the posts are being called in from wordpress but the templates only are outputting the HTML and no content. The reason for 3 posts on a fresh install is because post/list.phtml does not filter post content from pages, etc.
RESOLUTION Create new template file post/listFixed.phtml
<?php $posts = $this->getPosts() ?>
<?php if (count($posts) > 0): ?>
<div class="post-list-wrapper">
<ol class="post-list">
<?php foreach($posts as $post): ?>
<li class="item<?php if ($post->isSticky()): ?> featured is-sticky<?php endif; ?> <?php echo $post->getPostFormat() ?>">
<?php echo $post->getPostContent() ?>
</li>
<?php endforeach; ?>
</ol>
<?php echo $this->getPagerHtml() ?>
</div>
<?php endif; ?>
Use this block code:
{{block class="FishPig\WordPress\Block\Post\ListPost" name="wp.post.list" template="post/listFixed.phtml"}}
ADDITIONAL NOTES Once I had this working, I was able to take code snippets from FishPig: Recent Posts Block which was written for Magento1 and migrate it to the new code-base for Magento2, allowing me to filter out the pages, add links and featured images, and filter by category, etc.
Don't forget to flush cache, recompile, etc after adding the new template.
Hi @MMcConn, thanks for the feedback and notes.
This error occurs beacuse in the usual flow of the extension, the ListPost block has a renderer child container which contains separate block for each post data item (name, image, excerpt, categories etc). When including the ListPost block directly, this isn't set.
I have just released an update that fixes this issue by checking for the existence of the 'renderer' child container and if it isn't found, a fallback template is used. This template is post/list/renderer/default.phtml.
This template is a single template that contains all of the post data, rather than separate templates for each data item.
You can specify a custom template to fall back on by using the setRendererTemplate() method:
{{block class="FishPig\WordPress\Block\Post\ListPost" name="wp.post.list"
renderer_template="post/list/renderer/custom.phtml"}}
This should fix the issue so I will close this but if you have any questions then please reopen and comment.
PLATFORM
EXTENSION
PROBLEM STATEMENT Created a Page in Magento and added the following code into the content and the page listed the numberings but no content.
{{block class="FishPig\WordPress\Block\Post\ListPost" name="wp.post.list" template="post/list.phtml"}}