Magento Fishpig how to get post image by id - magento

I have use Fishpig extension in my website.
But i need to show Next and Previous link with it's appropriate featured image.
Can anyone please provide appropriate suggestion for this requirement.
Thanks,

The following code loads a post with the ID of 5 and if a featured image is set, it displays the image and a link to the post.
<?php $post = Mage::getModel('wordpress/post')->load(5) ?>
<?php if ($post->getId()): ?>
<?php if ($image = $post->getFeaturedImage()): ?>
<a href="<?php echo $post->getPermalink() ?>">
<img src="<?php echo $image->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
</a>
<?php endif; ?>
<?php endif; ?>
You can find more information on how to get different sized images from the featured image object at the URL below:
https://fishpig.co.uk/magento/wordpress-integration/post-images/

The following article explains how to get an image object from a post object.
https://fishpig.co.uk/magento/wordpress-integration/post-images/
Specifically:
<?php // $post is already defined ?>
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
<a href="<?php echo $post->getPermalink() ?>">
<img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
</a>
<?php endif; ?>

Related

Product images are serving from different paths on Product detail page and in sitemap

Product images are serving from different paths in view page & in sitemap.
1) product view page : media/catalog/product/W/i/image-name.jpg : link1
2) http://sitename.com/media/sitemap.xml : media/product/ee7/image-name.jpg : link2
but i want product images should serve from same path in both links:
media.phtml
<?php
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$dexxtz = Mage::helper('productzoom');
$dexxtz->getCss();
$dexxtz->getJs();
?>
<ul id="etalage">
<li>
<img class="etalage_thumb_image"
src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getImage()); ?>" />
<img class="etalage_source_image" title="<?php echo $_product->getImageLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image'), true); ?>" />
</li>
<?php
foreach ($this->getGalleryImages() as $_image) {
if(Mage::registry('current_product')->getImage() != $_image->getFile()) { ?>
<li>
<img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>" />
<img class="etalage_source_image" title="<?php echo $_image->getLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()), true); ?>" />
</li>
<?php
}
}
?>
</ul>
For delivering images in the frontend you should always use this call <?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage()); ?> as it utilizes the Magento cache, if enabled.
Definately not default Magento is this path media/product/ee7/image-name.jpg - all product media related stuff is in media/catalog/product. It might be that you have an extension that uses media/product to store and server images - but this is not default Magento.
Please check your extensions, especially how the links in the sitemap are created.

Check If Magento Product Has Thumbnail

I want to display a thumbnail image on a product page only if it exists. Currently it shows the placeholder image if a thumbnail image is not selected. I suppose I need to just wrap that around an if statement but do not know the method (if there is one) to check if the thumbnail image exists. Here is the code used to display the thumbnail:
<img id="slide-img-1" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(163, 100); ?>" /></a>
Use the following:
<?php if(!($_item->getThumbnail() == "no_selection")): ?>
<div class="image-holder">
<img class="thumbnail-image"
src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->constrainOnly(true)->resize(800); ?>"
alt=""
title="" />
</div>
<?php endif; ?>
If a thumbnail exists for the product then it should be set on the $_product instance. So you can use that in your condition, see below.
<?php if($_product->getThumbnail()): ?>
<img id="slide-img-1" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(163, 100); ?>" /></a>
<?php endif; ?>

Magento SEO Pagination like /page/2

i am trying to play around with pager.phtml, basicaly i do not like the ?p=2 etc that magento use.
I have come through this code that will change the pagination to what i want but this brings of course 404 pages as there is no /page/2 etc.
Should i use a rewrite rule?Can somebody point me on this?
<div class="pages">
<strong><?php
$url= ($this->getCurrentPage()==1)?
$this->getPagerUrl(array($this->getOrderVarName()=>$order, $this->getDirectionVarName()=>$direction,$this->getPageVarName()=>null )).'/':
$this->getPagerUrl(array($this->getOrderVarName()=>$order, $this->getDirectionVarName()=>$direction,$this->getPageVarName()=>null )).'/';
echo $this->__('Page:') ?></strong>
<ol>
<?php if (!$this->isFirstPage()): ?>
<li>
<a class="previous<?php if(!$this->getAnchorTextForPrevious()): ?> i-previous<?php endif;?>"
href="<?php echo $url.'p='.($this->getCurrentPage()-1);?>" title="<?php echo $this->__('Previous') ?>">
<?php if(!$this->getAnchorTextForPrevious()): ?>
<img src="<?php echo $this->getSkinUrl('images/pager_arrow_left.png') ?>" alt="<?php echo $this->__('Previous') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForPrevious() ?>
<?php endif;?>
</a>
</li>
<?php endif;?>
<?php
$pages_Num= ($this->getTotalNum()%$this->getLimit())?(($this->getTotalNum()/$this->getLimit())+1):$this->getTotalNum()/$this->getLimit();
for($_page=1;$_page<=$pages_Num;$_page++){
if($this->getCurrentPage()==$_page) echo '<li class="current"><a class="current" href="'.$url.'page/'.$_page.'">'.$_page.'</a></li>';
else echo '<li>'.$_page.'</li>';
}
?>
<?php if (($this->getCurrentPage()+1)<$pages_Num): ?>
<li><a class="next<?php if(!$this->getAnchorTextForNext()): ?> i-next<?php endif; ?>"
href="<?php echo $url.'p='.($this->getCurrentPage()+1);?>" title="<?php echo $this->__('Next') ?>">
<?php if(!$this->getAnchorTextForNext()): ?>
<img src="<?php echo $this->getSkinUrl('images/pager_arrow_right.png') ?>" alt="<?php echo $this->__('Next') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForNext() ?>
<?php endif;?>
</a></li>
<?php endif;?>
</ol>
</div>
First, you need to create a custom router which will parse the requested URL.
The method match () of the router may be implemented with this piece of code like this:
public function match(Zend_Controller_Request_Http $request) {
$this->_beforeModuleMatch();
$url = $request->getRequestUri();
$suffix = Mage::getStoreConfig('catalog/seo/category_url_suffix');
$pagerUrlFormat = "\/page\/([0-9]+)";
if (preg_match('/' . $pagerUrlFormat . preg_quote($suffix, '/') . '/', $url, $match)) {
$url = str_replace($match[0], $suffix, $url);
$request->setRequestUri($url);
$path = $request->getPathInfo();
$path = str_replace($match[0], $suffix, $path);
$request->setPathInfo($path);
$request->setParam('p', $match[1]);
return true;
}
return false;
}
This code will generate a URL of such a kind: http://example.com/category/p/2.html
NB! Please note that the code above hasn't been tested. It's just a simplified version of the more advanced code that is used in our SEO module (SEO Suite Ultimate)
Here is the description of the feature that does what you actually need:
Ability to create a pager URL format for paginated pages Examples:
-page[page_number] will transform URL into /mobile-phones-page2.html /p/[page_number] will transform URL into /mobile-phones/p/2.html

Dynamic Magento Top-Level Category Pages

I'm redesigning a client's top-level category pages and I would like to future-proof the design by making it dynamic. To further clarify, I want it so whenever the client adds, edits or removes a category below the current level, it would reflect that on the frontend without the need of editing code.
Now, I have come across some blog posts on the topic and even a Stack forum post:
http://www.templatemonster.com/help/magento-listing-sub-categories-on-a-category-page.html
how to display thumbnail from category using getThumbnailUrl() in Magento
However, these are both handling it differently. The Stack post also lead me to:
http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/
Which I found out I needed to add the functionality for pulling the Thumbnail Image (way to go Magento). BUT, this is what I need! The end goal here is to use the Thumbnail Image on the backend of the Category, NOT the Image. We're using the Image elsewhere, as intended. I also would like to be able to pull in the category description from the backend to the frontend for the purpose of adding some extra information such as links, a true description, etc.
If there anyone who can help me? I went through the above examples and links and still, the Thumbnail images were not pulling to the frontend and overall, I'm just getting some weird behaviour. Any tips would be appreciated as I research this further myself.
Thank you!
Please Try below code. I have implemented the same with this
<?php $category_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."catalog/category/"; ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="static-page-listing static-page-listing1">
<ul class="products-grid">
<?php $num = 0; ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()):
$num++;
$selImage = "SELECT value FROM catalog_category_entity_varchar WHERE attribute_id = '126' AND entity_id = '".$_category->getId()."'";
$catImage = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne($selImage);
if(!$catImage) $catImage = "no_image.jpg"; ?>
<li class="category-item <?php if($num%2==0) echo 'item-right'?>">
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<div style="float:left; width:100%;">
<img src="<?php echo $category_path.$catImage?>">
</div>
<div>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<h6 style = "color:red;">VIEW ALL</h6>
</div>
</a>
</li>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
NEW UPDATE:
The below code works:
<?php echo $cur_category->getDescription(); ?>
However, you need to be sure to check your Scopes! Not realizing my individual Store Scopes were not checked off to follow the "All Scopes" default, I fixed that and the above code worked for me when added to the "DESCRIPTION" area!
Thanks Stack!
PREVIOUS UPDATE:
I now have code working that I found online, it involved me adding a function to pull the category thumbnail image. It works! Here is the mark-up for the template:
<div class="category-products">
<ul class="products-grid">
<?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
}
elseif ($categorycount == 3){
$class = "last";
}
else{
$class = "";
}
?>
<li class="item <?=$class?>">
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<img src="<?php echo $cur_category->getThumbnailUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($cur_category->getName()) ?>" />
</a>
<h2>
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<?php echo $this->htmlEscape($cur_category->getName()) ?>
</a>
</h2>
<p>
DESCRIPTION
</p>
</li>
<?php
endif;
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}
else{
$categorycount++;
}
endforeach;
endif;
?>
</ul>
Now, where you see "DESCRIPTION," I would like to pull the category description data from the backend and have it output there. Basically, allowing dynamic creation/revision of top-level category pages.
How can I pull the description though? I'm not an expert in Magento, maybe I'm missing something basic but I can't get it working.
Thank you!

Magento: Display all images on the product page (view.phtml)

I can see how media.phtml (with Cloud Zoom extension) is listing all the images on the product page by help of $this->getGalleryImages():
<?php foreach ($this->getGalleryImages() as $_image): ?>
<?php ... ?>
<?php endforeach; ?>
But when I use $this->getGalleryImages() in view.phtml which is the catalog product page template, it doesn't return or output anything. However, this would only print the first image on the product page:
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(300, null);?>" alt="<?php echo $this->htmlEscape($this->getImageLabel());?>" title="<?php echo $this->htmlEscape($this->getImageLabel());?>" />
My question is how can I iterate through and display all the product images on the product page (view.phtml, not media.phtml)? Basically, I want them all on display on the page without thumbnailing or zooming or anything, just plain big images, one after another.
Thanks!
Here is the code for showing product image gallery..
Thanks,
Jeet
<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(108,90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php } ?>
<?php } ?>

Resources