Question

I'm trying to create a slider on the homepage of my Magento site. I am totally new to Magento and have someone else on our team coding most of that stuff after realizing how far into the deep end I jumped.

My issue: I'm trying to pull custom posts from WP (with the paid advanced custom fields extension) to display an image that will go into a slider.

I'm stuck at the most basic part - pulling in a list of Wordpress posts.

I created a new file: mytemplatedirectory/default/template/home/slider.phtml with

<?php $posts = $this->getPosts() ?>
<?php foreach ($posts as $_post) : ?>
     <?php echo $post->getPostContent() ?>
<?php endforeach ?>

and I put this into the CMS page in the Magento admin:

{{block type="core/template" template="home/slider.phtml"}}

But not even the default post is showing up.

If anyone has any guidance that would be extremely helpful. The beginning steps are what are throwing me off but it would also be nice to have help pulling the custom post and the advanced custom field (although it seems that Fishpig's documentation makes this pretty simple).

Thanks in advance! Sorry for such an amateur question.

Was it helpful?

Solution

The block type you're using does not include the getPosts() method, which is the reason your call to this returns nothing. If you change the block type to 'wordpress/sidebar_widget_posts' then the call to getPosts will return a post collection object.

The following link explains a little bit more about how to include this block and what you can do with it:

Display WordPress Blog Posts on the Magento homepage

OTHER TIPS

Figured this out with Ben's help (who I believe is the creator of the excellent Fishpig extension).

I created a custom post (with the Custom Post Type UI plugin for WP) and a custom field (with the Advanced Custom Fields plugin for WP).

On my Homepage in the CMS I added in the content area

{{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" post_type="slider_home" template="wordpress/sidebar/widget/slider_home.phtml"}}

In that block, slider_home is my post type and slider_home.phtml is a new file I created that pulls the code from wordpress/sidebar/widget/posts.phtml but customizes it to my need.

Within the loop in slider_home.phtml I took out what was currently there and added:

<?php $image = $post->getMetaValue('image'); ?>
<?php $url = $post->getMetaValue('url'); ?>
<a href="<?php echo $url; ?>" target="_blank">
  <img src="<?php echo $image; ?>" />
</a>

which is pulling in the custom fields I made in Wordpress. works perfectly and now my client will be able to update their Magento site through the Wordpress CMS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top