• Home
    • Cool Knowledge base
    • Light Knowledge base
    • Help Desk
    • OnePage Documentation
  • Services
    • Main Services
    • PPC Services
    • SEO Services
    • SMM Services
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Forum
    • Forums
    • Forum Topics
    • Topic Details
    • Ask Question
  • Pages
  • Contact

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

VideoJS – multiple source demo

2022-03-08

Add custom field to Woocommerce tab

2022-03-07

Surror Product Tabs for WooCommerce

2022-03-07
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram Pinterest VKontakte
SEO & Website build tips SEO & Website build tips
  • Home
    • Cool Knowledge base
    • Light Knowledge base
    • Help Desk
    • OnePage Documentation
  • Services
    • Main Services
    • PPC Services
    • SEO Services
    • SMM Services
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Forum
    • Forums
    • Forum Topics
    • Topic Details
    • Ask Question
  • Pages
  • Contact
SEO & Website build tips SEO & Website build tips
Home»Magento»Add Featured Image on AW-blog magento
Magento

Add Featured Image on AW-blog magento

OxfordBy Oxford2017-08-14Updated:2019-01-15No Comments2 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

Bit of a late reply, but here’s how to add a Featured Image field to a post:

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

Somewhere 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 finally, add a “featured_image” column to the aw_blog table in your database. Use the type VARCHAR(255) or something.

Now in your template files, you can access the featured image using the getFeaturedImage() method. For example in blog.phtml (the blog listing page) you could get the featured image for each post by putting the following code in the foreach loop:

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

Hi
Thanks for the code but I was also having issue with the featured image save in blog. I have checked and found that image is not being added to the blog data so its not added into database. I have made a small change and its fixed issue for me.

You just need to add below line

  $model->setFeaturedImage($_FILES[‘featured_image’][‘name’]);

before

$model->save();

in app/code/community/AW/Blog/controllers/Manage/BlogController.php file.

Thanks

 

https://forum.aheadworks.com/featured-image-t3821.html

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Avatar photo
Oxford

Related Posts

how to install magento 2.3.1 on cyberpanel enterprise

2021-09-29

How to Create GDPR Consent Form

2020-05-09

Nostrum et delectus modi fuga

2020-04-28

Quasi distinctio molestiae quibusdam excepturi quia accusamus

2020-04-28
Recent Posts
  • VideoJS – multiple source demo
  • Add custom field to Woocommerce tab
  • Surror Product Tabs for WooCommerce
  • How To Scrape Amazon at Scale With Python Scrapy, And Never Get Banned
  • Compile a Jekyll project without installing Jekyll or Ruby by using Docker
August 2017
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« Jan   Sep »
Tags
app branding culture design digital Docly docs etc faq fashion featured fitness fix github Helpdesk Image issue leisure lifestyle magento Manual marketing memecached Photography picks planing seo sequrity tips Travel trending ui/ux web WordPress 爬虫
Editors Picks

Fujifilm’s 102-Megapixel Camera is the Size of a Typical DSLR

2021-01-05
Top Reviews
8.9

Which LED Lights for Nail Salon Safe? Comparison of Major Brands

By Oxford
8.9

Review: Xiaomi’s New Loudspeakers for Hi-fi and Home Cinema Systems

By Oxford
70

CES 2021 Highlights: 79 Top Photos, Products, and Much More

By Oxford
Advertisement
Demo
  • Facebook
  • Twitter
  • Instagram
  • Pinterest
About Us
About Us

Your source for the lifestyle news. This demo is crafted specifically to exhibit the use of the theme as a lifestyle site. Visit our main page for more demos.

We're accepting new partnerships right now.

Email Us: [email protected]
Contact: +1-320-0123-451

Facebook Twitter Instagram Pinterest YouTube LinkedIn
Recent Posts
  • VideoJS – multiple source demo
  • Add custom field to Woocommerce tab
  • Surror Product Tabs for WooCommerce
  • How To Scrape Amazon at Scale With Python Scrapy, And Never Get Banned
  • Compile a Jekyll project without installing Jekyll or Ruby by using Docker
From Flickr
Ascend
terns
casual
riders on the storm
chairman
mood
monument
liquid cancer
blue
basement
ditch
stars
© 2025 Designed by 九号资源网.

Type above and press Enter to search. Press Esc to cancel.