gpt4 book ai didi

html - magento 中 aw 博客文章的广告缩略图

转载 作者:行者123 更新时间:2023-11-28 01:38:26 25 4
gpt4 key购买 nike

在 magento 1.8.1 中,我在 aw blog 帖子标题和每个标题旁边的 aw blog 侧边栏小部件中添加了缩略图

我做了这些:

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

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

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

并在数据库中的 aw_blog 表中添加了一个“featured_image”列。使用类型 VARCHAR(255) default 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 中的正确位置,但它们没有显示在前端

最佳答案

在你的blog.phtml subst

<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" />

希望对您有所帮助。

关于html - magento 中 aw 博客文章的广告缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27249542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com