0
votes

I'm using Ben's fishpig code that puts related post excerpts on the frontpage: http://fishpig.co.uk/magento/wordpress-integration/services/recent-posts-block/#code

However, I've managed to put this code to use on both the front page and in a custom tab CMS block but I can't work out how to get the featured image to show along with the excerpt.

FRONT PAGE XML

**
* Display a list of your 5 most recent WordPress Posts
* Also include post excerpt, date and comment count
*
* {{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts"     post_count="5" title="Latest Posts" excerpt="on" excerpt_length="1" date="on"   comment_num="on" template="wordpress/sidebar/widget/categoryposts.phtml"}}
*/
-->
<reference name="head">
<action method="addItem"><type>skin_css</type><name>css/custom.css</name></action>
</reference> 

<reference name="content">
    <block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/categoryposts.phtml">
        <action method="setTitle"><title>Latest Posts</title></action>
        <action method="setPostCount"><post_count>5</post_count></action>
        <action method="setExcerpt"><display>on</display></action>
**HELP**--><action method="setFeaturedImage"><display>on</display></action>
        <action method="setDate"><date>on</date></action>
        <action method="setCommentNum"><comments>on</comments></action>
    </block>
</reference>

HERE IS THE CODE FOR THE CUSTOM TAB:

{{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" category_id="19" title="Latest Posts" excerpt="on" excerpt_length="1" date="on" comment_num="on" template="wordpress/sidebar/widget/categoryposts.phtml"}}

Thank you!

6

6 Answers

1
votes

To add an image, you would need to modify the recent posts template. The following code illustrates how to display an image from a Post model:

<?php if ($featuredImage = $post->getFeaturedImage()): ?>
    <div class="featured-image left">
        <a href="<?php echo $post->getPermalink() ?>" title="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/></a>
    </div>
<?php endif; ?>
0
votes

Please go to this path:

/app/design/frontend/base/default/template/wordpress/sidebar/widget/categoryposts.phtml

and replace this code for get featured image from WordPress.

<?php if ($featuredImage = $post->getFeaturedImage()): ?>
                <div class="featured-image left">
                    <a href="<?php echo $post->getPermalink() ?>" title="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"><img height="185" width="320" src="<?php echo $featuredImage->getFullSizeImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/></a>
                </div>
            <?php endif; ?>
0
votes

<action method="setFeaturedImage"><display>on</display></action> should be <action method="setThumb"><thumb>on</thumb</action>

0
votes
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
            <div class="featured-image left">
                <a href="<?php echo $post->getPermalink() ?>" title="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/></a>
            </div>
<?php endif; ?>

and you can:

$featuredImage->getFullSizeImage();

getThumbnailImage()
getMediumImage()
getLargeImage()
getFullSizeImage()
getPostThumbnailImage()
getAvailableImage()
getImageByType($type = 'thumbnail')
0
votes

Post Images in Magento WordPress Integration

WordPress allows you to add an image to a post or page and set this image as the 'featured image'. This image is then automatically resized into different sizes that can be modified in the WordPress Admin. A thumbnail of this image will display automatically against the post in your integrated blog, however it is possible to display a featured image where ever you have a Post model.

The following code will display a post's featured image as a link to the post page.

<?php // $post is already defined ?>
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
    <a href="<?php echo $post->getPermalink() ?>">
        <img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
    </a>
<?php endif; ?>

Firstly the code retrieves the featured image model by calling $post->getFeaturedImage() which returns an object of Fishpig_Wordpress_Model_Image. The code then calls $featuredImage->getAvailableImage() which returns the smallest version of the image it can find.

It is possible to get a specific sized image rather than just the first available image.

The follow methods are available:

<?php

    $image = $post->getFeaturedImage();

    // Get the URL of the thumbnail image
    echo $image->getThumbnailImage();

    // Get the URL of the medium sized image
    echo $image->getMediumImage();

    // Get the URL of the large image
    echo $image->getLargeImage();

    // Get the URL of the full size image (this will be the original uploaded image size)
    echo $image->getFullSizeImage();

    // Get the post thumbnail image URL
    echo $image->getPostThumbnailImage();

    // Work through these images and get the first available image
    echo $image->getAvailableImage();

?>

And You Need To Be Sure That The Post Already Have Feature Image.

-2
votes

in case noone else noticed the XML solution does work. just the XML provided above is missing a '/'

should be: on