Displaying image from RSS - image

I have this feed item via SimplePie:
<item>
<guid isPermaLink="false">tncms-asset-7f55e8da-c801-11e2-9a4d-001a4bcf887a</guid>
<title>Parts of old span may be used in bridge repair</title>
<author>Author Person</author>
<link>http://www.mysite.com/a.html</link>
<description><![CDATA[Description Here.]]></description>
<pubDate>Tue, 28 May 2013 18:45:00 -0700</pubDate>
<enclosure url="http://mysite.com/happyLilPic.jpg" length="512" type="image/jpeg" />
</item>
I can get everything else to show except the image with the following:
<?php
foreach ($feed->get_items() as $item):
?>
<div class="item">
<h3><?php echo $item->get_title(); ?></h3>
<p><?php echo $item->get_description(); ?></p>
<?php echo "<img src=\"" . $item->get_enclosure['url'][0] . "\">"; ?>
<br><br>
</div>
<?php endforeach; ?>
What am I doing wrong with the enclosure???

get_enclosure() returns a single array location containing a SimplePie_Enclosure object. The documentation shows it this way:
if ($enclosure = $item->get_enclosure())
{
echo $enclosure->embed();
}
That uses the <embed> tag though, which is not what you want. The documentation for the Enclosure Object Lists many methods. The one I think you want is get_link(), so you would change your image tag code like this:
if ($enclosure = $item->get_enclosure())
{
echo "<img src=\"" . $enclosure->get_link() . "\">";
}

Related

Magento2 Catgory Filter

How can I filter Magento2 multiple category ?
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"><listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="templates" xsi:type="array">
<item name="filters" xsi:type="array">
<item name="select" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
<item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
</item>
</item>
</item>
</item>
</argument>
</filters>
Please Help me how can I add category filter
Recently I got a chance to rewrite Magento’s layered navigation standard functionality. The request was very specific as the client wanted to keep all of the “filters” visible all the time. For example if you wish to filter your results by Color (let’s say you have yellow, green, red, blue and magenta) products are filtered but the layered navigation displays all filters. This way a costumer can re-filter the products in current category without needing to return to the category's view.
Files that are used for layered navigation are situated in app /design/frontend/base/default/template/catalog/layer/ folder. File used for layered navigation is view.phtml – it shows us all of the filters when we click on a category. File used for active state is state.phtml – when we click on one of the filters it is responsible for the results – so we’re gonna edit this one. So copy the state.phtml from base to your package or theme.
This is the original code in state.phtml:
<?php $_filters = $this->getActiveFilters() ?>
<?php if(!empty($_filters)): ?>
<div class="currently">
<p class="block-subtitle"><?php echo $this->__('Currently Shopping by:') ?></p>
<ol>
<?php foreach ($_filters as $_filter): ?>
<li>
<?php echo $this->__('Remove This Item') ?>
<span class="label"><?php echo $this->__($_filter->getName()) ?>:</span> <?php echo $this->stripTags($_filter->getLabel()) ?>
</li>
<?php endforeach; ?>
</ol>
<div class="actions"><?php echo $this->__('Clear All') ?></div>
</div>
<?php endif; ?>
Since we’re going to need url path of current category add this code before “currently” div block
<?php $obj = new Mage_Catalog_Block_Navigation(); ?>
<?php $_current_category=$obj->getCurrentCategory()->getUrlPath(); ?> //getting url path of current category
<?php $subs = $obj->getCurrentCategory()->getAllChildren(true); ?> //getting ids of subcategories of current category
Now we’re going to edit “currently” div, I renamed my to state, since it doesn’t show just current filter state anymore. Experienced Magento developers will notice that not all of the code is programmed Magento-way, but when I programmed it (Magento CE 1.4.2. ) Magento still didn’t have needed functions. I guess they didn’t expect from someone to use layered navigation this way. So, here we go!
<?php if(!empty($_filters)): ?>
<div class="state">
<p class="block-subtitle"><?php echo $this->__('Currently Shopping by:') ?></p>
<dl>
<?php foreach ($_filters as $_filter): ?>
<dd>
<ol>
<?php $attributemodel=$_filter->filter->_data["attribute_model"]; ?> // getting attribute model that has all filter options in it from currently active filter
<?php $attroptions=$attributemodel->getSource()->getAllOptions();?> // getting attribute options (filters) from attribute model
<?php $_categ= Mage::getModel('catalog/category');?> // object containing all categories and their information
<?php foreach($subs as $cat_id): ?>
<?php $_categ->load($cat_id)?> //get the subcategory you need
<?php $collection = $_categ->getProductCollection(); ?> //get the product collection (object containing all product information)
<?php $collection->addAttributeToSelect('color')?> // get the desired attribute
<?php endforeach; ?>
The next thing that needs to be done is to extract the information from attribute model and assemble links. Each of attribute options ($attroptions) contains attribute value (id) and attribute label.
<?php foreach($attroptions as $attr): ?> // get value and label of each attribute
<?php $count=0; ?>
<?php if($attr["value"]!=""): ?>
<?php $val=$attr["value"] ?>
<?php $collection->addFieldToFilter(array(array('attribute'=>'themes','gt'=>10)))?> // collection of attribute values and labels for all values
//greater then 10 (in this case attribute values range was 18-39)
<?php $proddata=$collection->getData() ?> // get product data for all attribute values
<?php if($attr["label"]!= $this->stripTags($_filter->getLabel())): ?> // make a nice looking label
<?php foreach($proddata as $prod):?>
<?php if($prod["type_id"]=="configurable"): ?> // in this store all products were configurable
<?php $split=split(",", $prod["color"]);?> // get the attribute values that correspond with one product (a product may have more
// then one attribute value and they're separated by commas that's why we split the string with "," as deliminator)
Even thought you set your attribute to Filterable(with results) you still have to count the products in order to output only attribute values that have product count >0.
<?php foreach($split as $color): ?> //check out how many products have the same attribute value
<?php if($color==$attr["value"]): ?>
<?php $count++;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;?>
<?php endforeach; ?>
<?php if($count>0):?> // check if any product has that attribute value
<li><a href="<?php echo $this->getUrl('').$_current_category ?>?color=<?php echo $attr["value"]?>" ><?php echo $attr["label"]; ?></a></li> // if not currently active filter make a link
<?php endif; ?>
<?php else:?>
<li class="current"> <?php echo $this->stripTags($_filter->getLabel()); ?></li> // if currently active filter write out the label
<?php endif;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?> // ending the first for loop (foreach($filters as $filter))
</ol>
</dd>
</dl>
<a class="all" style="float:right;" href="<?php echo $this->getClearUrl()?>">All</a> // show all products, return from current state back to category view
</div>
<?php endif; ?>
And that’s it. Our task of keeping the filters visible all the time is finished 🙂 . Now where ever you go using layered navigation you’ll be able to simply re-filter the products in current category without the need to go back to category view. And for the end a brief warning – some code here isn’t programmed Magento-way, because needed functions weren’t available. I hope I explained the problem and solution well enough :).
Cheers!

I have a script, in yii. That almost does the job, need just a little push

I am not a programmer by any means. I purchased the script and have spent two weeks and many variations trying to get the code to do what I need. It is 'almost' there.
<div id="step-2" style="position:absolute; center:overflow-y:;">
<?php if($images): ?>
<?php foreach ($images as $img => $data): ?>
<a href="javascript:;" class="pin-img">
<img src="<?php echo $img ?>" />
</div>
</a>
<?php endforeach; ?>
<?php else: ?>
<h2><?php echo Yii::t('yii', 'No relevant found!') ?></h2>
<?php endif ?>
</div>
It returns the images from a site. It only lets me select the first image. Even though all images are displayed. Only one is actually clickable. If I hover over each of the images I see the javascript href. I understand that to be some sort of place holder. that just makes the browser show the hand.
I just need the script to allow each item to be a choice for reaction.
http://silenceisnotawkward.com/Sinapin/Script/# is the live code.
I have made a test user
Test=user
Password =password in case anyone wants to see what the site does.
http://www.ew.com/ew/ is a good link to pin from website and see the behavior.
I didn't look at your site, but looks like you are confusing your nesting of HTML tags, because you introduced a end-of-dev tag in your link.
<div id="step-2" style="position:absolute; center:overflow-y:;">
<?php if($images): ?>
<?php foreach ($images as $img => $data): ?>
<a href="javascript:;" class="pin-img">
<img src="<?php echo $img ?>" />
<!-- I removed the < / div > from here -->
</a>
:
<?php endforeach; ?>
</div
>
HINT: I indented the code to make it more readable, Try doing the same with your code you posted and see where it leads you.

Joomla change leading articles html on the blog category page

I would like to change the leading articles html structure for the blog category page in Joomla 2.5.
It has to be like this
<dl>
<dt>intro-image</dt>
<dd>
<h3>article-title</h3>
<var>published-date</var>
intro-text
</dd>
</dl>
I copied blog.php file into my-template/html/com-content/category/ and modified it
<?php if (!empty($this->lead_items)) : ?>
<?php foreach ($this->lead_items as &$item) : ?>
<dl>
<dt></dt>
<dd>
<?php
$this->item = &$item;
echo $this->item->introtext;
?>
</dd>
<?php
$leadingcount++;
?>
</dl>
<?php endforeach; ?>
But as you see I only managed to show the intro text. How can intro image, article title and published date be displayed on their places? Are there more files, which have to be modified?
I appreciate any help. Thank you.
Half way there. Here is the code but I'm not sure what you mean by the intro image. Is it part of the article? Please explain and I might be able to get it working fully:
<?php foreach ($this->lead_items as &$item) : ?>
<dl>
<dt>
<?php
$params = JComponentHelper::getParams( 'com_content' );
$this->item = &$item;
$images = json_decode($item->images);
if (isset($images->image_intro) and !empty($images->image_intro)) {
$imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />';
}
?>
</dt>
<dd>
<h3><?php echo $this->item->title; ?></h3>
<var><?php echo $this->item->publish_up; ?></var>
<?php echo $this->item->introtext; ?>
</dd>
<?php $leadingcount++; ?>
</dl>
<?php endforeach; ?>

Magento: display multi-selection as a list with unique ID' s so list item can be changed to an image using CSS

I figured out how to display my custom multiselection attributie as a list but havent been able to figure out how to add an ID or class to every list item. This would allow me to display an image using CSS instead of text.
Hope you guys can help me. By the way, this is the code I use to display my custom attribute "rating" as a list:
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)): ?>
<ul><li><?php
$_comma = ",";
$_list = "</li><li>";
echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) ?>
</li></ul>
<?php endif; ?>
</div>
Without knowing the exact format of the return of your function, I can't be 100% sure, but I think this would do the trick:
<div>
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)):?>
<ul>
<?php $i=0?>
<?php foreach(explode(',', $_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) as $value) : ?>
<li id="value_<?php echo $i?>"><?php echo $value ?></li>
<?php $i++ ?>
<?php endforeach ?>
</ul>
<?php endif; ?>
</div>
It would probably be a little easier to just modify your return to give you back an array, but if the return is a comma separated list and not easy to change, then explode should do the trick.

Wordpress: show featured image with subcategory

I'm using this to generate a list of sub-pages that are a parent of 10 and images:
<ul>
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="http://mydomain.com/image.gif" alt="" />'); ?>
</ul>
It works, but the problem is I don't know how to get the post featured image there instead. I tried this but it did not work:
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="' . the_post_thumbnail(array(100,50)) . '" alt="" />'); ?>
Obviously I'm missing something.
Any suggestions would be appreciated.
To display the page titles along with the images, you should use get_pages()
<?php
$pages = get_pages('child_of=10');
if ($pages) {
echo '<ul>';
foreach ($pages as $page) {
echo '<li><a href="'.get_permalink($page->ID).'">';
echo get_the_title($page->ID);
echo get_the_post_thumbnail($page->ID);
echo '</a></li>';
}
echo '</ul>';
}
?>
The get_the_post_thumbnail function returns HTML not the image url.
Instead use
<?php $image_url = wp_get_attachment_image_src( get_post_thumbnail_id(10), array(100,50) ); ?>
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="' . $image_url . '" alt="" />'); ?>
This will list all sub-pages of page id 10, with thumbnail of page id 10. If you want the thumbnails of the sub-pages instead of parent page, you will have to write custom code instead of wp_list_pages function(as explained by Indranil).

Resources