1

I use Fishpig extension to show my blog posts in Magento.

In Wordpress with below code i show a custom fallback-image if there is NOT a featured image set (in Wordpress admin).

<?php 
        if ( has_post_thumbnail() ) 
        {
        the_post_thumbnail();
        }
        else 
        { ?>
        <img src="<?php bloginfo('template_directory'); ?>/images/compressport-r2.jpg" alt="<?php the_title(); ?>" />
    <?php 
        } ?>

But on the Magento frontend its not showing this image? Its only showing the image while its really set as Featured image (in Wordpress admin).

What do i have to change in the Magento Wordpress template code to make this work?

--- Update 1 ---

It works with below adjustment, but can i wright it shorter?:

                        <?php if ($this->canDisplayImage() && $post->getFeaturedImage()): ?>
                        <div class="post-image-wrap">
                            <img src="<?php echo $post->getFeaturedImage()->getFullSizeImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
                        </div>

                        <div class="wordpress-msg">                         
                            <h3><?php echo $this->htmlEscape($post->getPostTitle()) ?></h3>
                            <?php if ($this->canDisplayDate()): ?>
                            <p class="post-date"><?php echo $post->getPostDate() ?></p>
                            <?php endif; ?>
                        </div>

                        <?php else: ?>

                        <div class="post-image-wrap">
                            <img src="http://blog.futurum.cc/wp-content/uploads/2015/06/compressport-r2.jpg"/>
                        </div>

                        <div class="wordpress-msg">                         
                            <h3><?php echo $this->htmlEscape($post->getPostTitle()) ?></h3>
                            <?php if ($this->canDisplayDate()): ?>
                            <p class="post-date"><?php echo $post->getPostDate() ?></p>
                            <?php endif; ?>
                        </div>

                    <?php endif; ?>
1

1 Answer 1

1

You can get the post Feature image by this

<?php echo $post->getFeaturedImage() ?>

So you check the condition here

<?php if($post->getFeaturedImage()) :?>
     <img src="<?php echo $post->getFeaturedImage() ?>"/>
<?php else:?>
     <img src="...."/>
<?php endif;?>

Refer this Link

Update:

<div class="post-image-wrap">
    <?php if ($this->canDisplayImage() && $post->getFeaturedImage()): ?>
        <img src="<?php echo $post->getFeaturedImage()->getFullSizeImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
    <?php else: ?>
        <img src="http://blog.futurum.cc/wp-content/uploads/2015/06/compressport-r2.jpg"/>
    <?php endif; ?>
</div>
<div class="wordpress-msg">                         
    <h3><?php echo $this->htmlEscape($post->getPostTitle()) ?></h3>
    <?php if ($this->canDisplayDate()): ?>
    <p class="post-date"><?php echo $post->getPostDate() ?></p>
    <?php endif; ?>
</div>
1
  • Thanks that works. Can i get my code shorter (see above Update)?
    – Meez
    Jun 16, 2015 at 9:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.