【问题标题】:How to display blog posts with featured images on magento homepage?如何在 magento 主页上显示带有特色图片的博客文章?
【发布时间】:2012-06-02 13:22:00
【问题描述】:

我已经在我的 magento 站点中集成了 fishbig。(fishbig 用于将 wordpress 与 magento 集成)。现在帖子显示正常。

现在我需要获取帖子名称、发布日期、发布特色图片和发布链接,以便在主页中以幻灯片的形式显示。我怎么能得到那个?

【问题讨论】:

    标签: wordpress magento posts


    【解决方案1】:

    当我们将fishbig与magento集成时,我们可以在模板文件夹中有一个文件夹“wordpress”。(path:- app\design\frontend\base\default\template).

    我们可以创建我们的自定义文件夹,如“home”。因为我们需要创建一个名为“slider.phtml”的.phtml文件。

    以下代码返回帖子名称、帖子特色图片等...

    <?php $posts = $this->getPosts() 
    
    if (count($posts) > 0): ?>
    
    
    
    <?php 
          foreach($posts as $post): ?>
          <?php 
    
         $image_url = $post->getFeaturedImage()->getFullSizeImage(); // Featured image
              $post_link = $post->getPermalink(); // Post link
              $post_date = $post->getPostDate(); // Post date
              $post_day = date('l', strtotime($post_date)); // Day of Post
              $post_title = $post->getPostTitle(); // Post Title
    
    <?php endforeach; ?> 
    
    <?php endif; ?>
    

    然后在主页幻灯片部分调用此模板,例如,

    <div class="home_banner">
      <?php
    $magento_block = Mage::getSingleton('core/layout');
    $blog = $magento_block->createBlock('wordpress/sidebar_widget_posts')->setTemplate('wordpress/home/homeslide.phtml');
    $blog->setPostCount(6);
    echo $blog->toHtml();
    ?> 
    </div>
    

    【讨论】:

      猜你喜欢
      • 2017-08-16
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多