Add WordPress featured image to RSS feed - image

I'm setting up an RSS to email campaign in MailChimp using my WordPress RSS Feed, and I want to include the featured image in my MailChimp template.
I've tried using this to add the image, which works, but it simply adds it to the content, which doesn't work for MailChimp section of the RSS code:
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Apparently, MailChimp wants it's "own" unique image element. Here's an example of what they want: http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns
but it looks like it's in a different RSS format. Here's what my RSS is outputting: http://pacmissions.org/dev/missions/zimbabwe-2012/feed/

I often have to create custom feeds for MailChimp, and find that a lot of the time I have to make somewhat 'hacky' changes like putting custom values into the limited standard fields that MailChimp supports.
Because of this I like to use the method described at Yoast ( http://yoast.com/custom-rss-feeds-wordpress/ ) to create a page that outputs a custom RSS feed.
There are couple of tweaks to make in order to get the featured image included as a field that MailChimp will recognise.
Firstly, you need to add the Media RSS namespace, which I usually do by adding to the opening <rss> tag:
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
Then in order to include the featured image inside the item:
<?php if(get_the_post_thumbnail()): ?>
<media:content url="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" medium="image" />
<?php endif; ?>
If you need to specify a particular image size to include, you'll need to use this code inside the item instead:
<?php if(get_the_post_thumbnail()): ?>
<media:content url="<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'imageSize'); echo $image[0]; ?>" medium="image" />
<?php endif; ?>
You can then grab this in MailChimp using the *|RSSITEM:IMAGE|* or *|FEEDITEM:IMAGE|* merge tags.

There seem to be plenty of examples of how to add the image to the top of the content in the feed, but not too many where you're creating a new tag. One potential issue is that creating a custom tag or something similar won't be a valid RSS format. If you're creating an XML document for your own usage it doesn't matter so much if the feed validates. Here's what I did, and you should easily be able to modify it slightly for the MailChimp use case.
In functions.php add (inside the theme folder: wp-content/themes/{your-active-theme-folder}):
function insertImageRSS() {
global $post;
preg_match("/(http:\/\/.*(jpg|jpeg|png|gif|tif|bmp))\"/i", get_the_post_thumbnail( $post->ID, 'thumbnail' ), $matches);
return $matches[1];
}
In the wp-includes/feed-rss2.php ( I used the enclosure tag, but haven't yet done the filesize calculation, so I used a placeholder ):
<?php if (get_the_post_thumbnail( $post->ID, 'thumbnail' ) != '') { ?><enclosure <?php echo 'url="' . insertImageRSS() . '"'; ?> length="1000" type="image/jpeg" /><?php } ?>

Related

Remove the HTML from renderField output

Is there any way I could strip html out of this?
<?php echo $this->form->renderField('monday'); ?>
In the back end theres a selection where you pick options that show up in a schedule but they are showing up as html and I need them to show up as plain text for the selection.
you can use php strip_tags function
<?php echo strip_tags($this->form->renderField('monday')); ?>
http://php.net/manual/en/function.strip-tags.php.
If you wanna keep some tags, look at the section allowable_tags
You should know that select and option are also html tags and will be removed if you use strip_tags. So you can allow those tags. You can modify your code like this
<?php $field = strip_tags(($this->form->renderField('monday')),'<select><option>');
echo $field;
?>

I want change page heading position

In Joomla Page heading showing inside of an article I want to change the position of page heading, is it possible to customize page heading position?
I had included following code in template/protostar/index.php
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif;
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && $this->item->paginationrelative)
{
echo $this->item->pagination;
}
?>
What you can do:
Just update one of the css files in the correct template to display the header correctly. If the header should only be reformatted on some pages and not all then you should be using different templates.
What you should do:
Otherwise (if you want to change the php instead) you can override the components/com_content/views/article/default.php using the standard joomla override method.
You can do both the above if necessary.
You should not need to override the index.php of your template in order to do this. However if you really want to i would use the code
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
}
Sorry if you want more you need to give more :)
PS. I am on joomla 2.5 but i know that for joomla 3 it is more or less the same thing.
Sources: http://forum.joomla.org/viewtopic.php?t=525350
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

How to display two currency in magento cart

I want to display two currencies in Magento's cart and invoice. I have make it in product page by this code
<div class="currency">
<?php if( Mage::app()->getStore()->getCurrentCurrencyCode() == 'USD'): ?>
<span class="price">(<?php echo round(Mage::helper('directory')->currencyConvert( $_product->getFinalPrice(), 'USD', 'AUD'), 2 ); ?>) AUD</span>
<?php else: ?>
<span class="price">(<?php echo round(Mage::helper('di`enter code here`rectory')->currencyConvert( $_product->getFinalPrice(), 'AUD', 'USD'), 2 ); ?>) USD</span>
<?php endif; ?>
</div>
and now I want to display this in the email invoice.
in the email template ti has this line
{{layout handle="sales_email_order_items" order=$order}}
looking up sales layouts we find app\design\frontend[package][theme]\layout\sales.xml
from there you can see the .phtml files used to render the items section of the email, edit the ones you need, keep in mind that these are also used on the front end.
if you want to separate the .phtml files so that the frontend and email template can use different files, copy/paste/rename sales_email_order_items in the .xml file and change the template= parts to the new templates, be sure that in your email template you change the handle stated above to what you renamed the layout to otherwise it'll use the original one.
your code should work fine, you may just need to change $_product->getFinalPrice() if it doesn't work and $_product may not be in the template or be a different class since your dealing with the the collection that deals with sales_flat_order rather than catalog_product

CodeIgniter : image upload on article

I'm building a website with MongoDB and Codeigniter where users can create articles (title + text) and after it (but before to submit), upload some pictures (images are not in the text).
I think i will use jquery.upload for it. But my question is how to do link between pictures and article (because img will be uploaded first), how to rename them ?, is there any good way to do this ?
jquery upload would work. and check if it is success then create new hidden input into the form and set its value as you wish to use.
While I've never attempted this feature, this is a hypothetical solution that popped in my head:
Create a unique string on your Create Article page, and insert it into your document as a hidden field. A random string of 6 characters or something would probably be sufficient.
When uploading the images, use that string as an identifier for what future post the images belong to. Use the string in the file name, path, DB entry, or whatever's useful for your scenario.
When the article itself is submitted, the unique string will allow it to be identified with the images, and you can work whatever magic you need to at that stage to fully commit everything together.
Keep in mind that you should have some sort of statistics and/or garbage collection regarding any images that are uploaded and then the related article is abandoned.
Add 'thumbnail' field in your table 'articles_table' . I removed the unnessary parts for simpler need.We will only use 'title' and 'thumbnail' as field.
View | create.php
<?php echo form_open_multipart('articles/insert'); ?>
Title <br>
<?php echo form_input('title','','id="title_input"'); ?><br>
Thumbnail<br>
<input type="file" name="file" size="20" />
<?php echo form_submit('Submit',"Submit"); ?>
<?php echo form_close(); ?>
Controller | articles.php
function insert()
{
//$this->articles_model->insert();
$this->articles_model->save();
redirect('articles/index');
}
Model | articles_model.php
function save($id=0)
{
$title=$this->input->post('title');
//Set the config
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpg|png|PNG';
$config['max_size'] = '1100';
$config['max_width'] = '11024';
$config['max_height'] = '1768';
$config['overwrite'] = FALSE;
//Initialize
$this->upload->initialize($config);
//Upload file
if( ! $this->upload->do_upload("file"))
{
//echo the errors
echo $this->upload->display_errors();
}
//If the upload success
$thumbnail = $this->upload->file_name;
if($id<1)
{
$data=array(
'title'=>$title,
'thumbnail'=>$thumbnail
);
$this->db->insert('articles_table',$data);
}
}

Retrieve product custom media image label in magento

I have a custom block loading products on my front page that loads the four newest products that have a custom product picture attribute set via:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(4);
What I am trying to do is grab the image_feature_front_right label as set in the back-end, but have been unable to do so. Here is my code for displaying the products on the front end:
<?php foreach($_productCollection as $_product) : ?>
<div class="fll frontSale">
<div class="productImageWrap">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4) ?>" />
</div>
<div class="salesItemInfo">
<p class="caps"><?php echo $this->htmlEscape($_product->getName());?></p>
<p class="nocaps"><?php echo $this->getImageLabel($_product, 'image_feature_front_right') ?></p>
</div>
</div>
I read that $this->getImageLabel($_product, 'image_feature_front_right') was the way to do it, but produces nothing. What am I doing wrong?
Thanks!
Tre
It seems you asked this same question in another thread, so to help others who might be searching for an answer, I'll anser it here as well:
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>
Your custom block would need to inherit from Mage_Catalog_Block_Product_Abstract to give access to that method.
You could also use the code directly from the method in the template:
$label = $_product->getData('image_feature_front_right');
if (empty($label)) {
$label = $_product->getName();
}

Resources