Fishpig整合 - 在头版上获取精选图片?

时间:2014-02-25 06:30:01

标签: fishpig

我正在使用Ben的fishpig代码,将相关的帖子摘录放在首页上: http://fishpig.co.uk/magento/wordpress-integration/services/recent-posts-block/#code

但是,我已设法将此代码用于首页和自定义选项卡CMS块中,但我无法弄清楚如何使特色图像与摘录一起显示。

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>

这是CUSTOM选项卡的代码:

{{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"}}

谢谢!

6 个答案:

答案 0 :(得分:1)

要添加图片,您需要修改最近的帖子模板。以下代码说明了如何显示Post模型中的图像:

<?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; ?>

答案 1 :(得分:0)

请走这条路:

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

并替换此代码以从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; ?>

答案 2 :(得分:0)

<action method="setFeaturedImage"><display>on</display></action>应为<action method="setThumb"><thumb>on</thumb</action>

答案 3 :(得分:0)

<?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; ?>

你可以:

$featuredImage->getFullSizeImage();

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

答案 4 :(得分:0)

Post Images in Magento WordPress Integration

WordPress允许您将图像添加到帖子或页面,并将此图像设置为&#39;特色图像&#39;。然后,此图像会自动调整为可在WordPress管理中修改的不同大小。此图片的缩略图将自动显示在您的集成博客中的帖子上,但是,只要您拥有Post模型,就可以显示特色图片。

  

以下代码会将帖子的精选图片显示为帖子页面的链接。

<?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; ?>

首先,代码通过调用返回Fishpig_Wordpress_Model_Image对象的$post->getFeaturedImage()来检索特色图像模型。然后代码调用$ featuredImage-&gt; getAvailableImage(),它返回它可以找到的最小版本的图像。

可以获得特定尺寸的图像,而不仅仅是第一个可用的图像。

  

可以使用以下方法:

<?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();

?>

你需要确保帖子已经有特色图片。

答案 5 :(得分:-2)

如果没有人注意到XML解决方案确实有效。只是上面提供的XML缺少'/'

应该是:         上