4

im trying to add a thumbnail image to aw blog posts header and into the aw blog sidebar widget next to the each headline

i did these:

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

change:

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

to

$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'
 ));

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

add

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

below the line

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

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

add

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 ;

      $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']);
}

below the line

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

And added a "featured_image" column to the aw_blog table in database. Use the type VARCHAR(255) default null and null enable .

and add

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>

to

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

below line

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

but in blogs page image address is showing instead of image

3

If the url is just shown you just need to wrap it in image tags right?

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
  • how to change the directory from 'media' to 'media/blogpic' ? – Moh3n Dec 1 '14 at 21:36
  • please ask this as a new question and specify whether you want the images to be saved in that directory or loaded from that directory – Toon Van Dooren Dec 2 '14 at 20:11
  • Hi @Moh3n , you can change the path like this: $path = Mage::getBaseDir('media') . '/blogpic/' ; – bestwebdevs May 31 '17 at 18:53
0

I have added a little check before

<?php if ($post->getFeaturedImage()): ?>
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'blog/'.$post->getFeaturedImage() ?>" alt="<?php echo $post->getTitle(); ?>" />
<?php endif;?>
0

For insert in Db "featured_image" column to the aw_blog table in database and insert the type VARCHAR(255) default null and null enable, what is the procedure? Tnx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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