广告缩略图到magento中的博客帖子

时间:2014-12-02 12:30:08

标签: html magento-1.8 php

在magento 1.8.1中我已将缩略图添加到aw blog帖子标题,并添加到每个标题旁边的aw博客侧边栏小部件中

我做了这些:

  

在app / code / community / AW / Blog / Block / Manage / Blog / Edit / Form.php

变化:

$form = new Varien_Data_Form(array(
    'id' => 'edit_form',
    'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
    'method' => 'post',
 ));

$form = new Varien_Data_Form(array(
    'id' => 'edit_form',
    'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
    'method' => 'post',
    'enctype' => 'multipart/form-data'
 ));
  

在app / code / community / AW / Blog / Block / Manage / Blog / Edit / Tab / Form.php

添加

$fieldset->addField('featured_image', 'image', array(
    'name' => 'featured_image',
    'label' => 'Featured Image'
));

以下

$fieldset = $form->addFieldset('blog_form', array('legend' => Mage::helper('blog')->__('Post information')));
  

在app / code / community / AW / Blog / controllers / Manage / BlogController.php

添加

if(isset($_FILES['featured_image']['name']) and (file_exists($_FILES['featured_image']['tmp_name']))) {
   try {
      $uploader = new Varien_File_Uploader('featured_image');
      $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
      $uploader->setAllowRenameFiles(false);

      // setAllowRenameFiles(true) -> move your file in a folder the magento way
      // setAllowRenameFiles(true) -> move your file directly in the $path folder
      $uploader->setFilesDispersion(false);

      $path = Mage::getBaseDir('media') . DS .'blogpic'.DS;

      $uploader->save($path, $_FILES['featured_image']['name']);

      $data['featured_image'] = $_FILES['featured_image']['name'];
   }catch(Exception $e) {

   }
}

// handle delete image
else {
   if(isset($data['featured_image']['delete']) && $data['featured_image']['delete'] == 1)
      $data['image_main'] = '';
   else
      unset($data['featured_image']);
}

以下

$model = Mage::getModel('blog/post');

并添加了一个" featured_image"列到数据库中的aw_blog表。使用类型VARCHAR(255)默认null和null enable。

并添加

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />

  

/app/design/frontend/base/default/template/aw_blog/blog.phtml

在线下

<?php foreach ($posts as $post): ?>
    <div class="postWrapper">
        <div class="postTitle">
            <h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>

问题是:图片保存在media/blogpic的正确位置,但它们没有显示在前端

2 个答案:

答案 0 :(得分:1)

blog.phtml

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).DS.'blogpic'.DS.$post->getFeaturedImage() ?>" alt="featuredImage" />

希望它有所帮助。

答案 1 :(得分:0)

将特色图像或缩略图图像添加到Magento版本的AWBlog而不进行编码的最简单方法如下:
- 在博客文章中,转到 SHORT CONTENT 文本字段
- 在该字段中输入您的图像URL

<img src="{{media url="wysiwyg/blogimages/myimages/your.jpg"}}" alt="folding chairs" />


- 在下面输入你的模糊


当您在博客概述中保存并打开博文时,您将看到精选的图像显示,其下方的内容为简洁。