Skip to content

Instantly share code, notes, and snippets.

@wcodex
wcodex / gist:6762367
Created September 30, 2013 11:17
Post View Count in WordPress
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
@wcodex
wcodex / gist:6791401
Created October 2, 2013 09:47
How to check for Magento Home Page
if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))):
echo "This is magento home page";
else
echo "Oops this is not home page,sorry";
@wcodex
wcodex / gist:6797110
Created October 2, 2013 17:16
Display or get new products in Magento store
$allproduct = Mage::getModel('catalog/product')->getCollection()->setOrder('entity_id','desc')->getData();
$_helper = $this->helper('catalog/output');
foreach($allproduct as $product){
echo '<div class="product_box">';
$obj = Mage::getModel('catalog/product');
$productid = $product['entity_id'];
$_product = $obj->load($productid); // Enter your Product Id in $product_id
$productName = $_product->getName();
$productDescription = $_product->getDescription();
@wcodex
wcodex / gist:6805244
Created October 3, 2013 05:06
How to add contact us form in CMS page. Create new CMS page as contact us and add following code
{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
@wcodex
wcodex / gist:6805266
Created October 3, 2013 05:08
Top linkes URL in Magento
//link for my account
<?php echo $this->getUrl('customer/account')?>">
//wishlist URL
<?php echo $this->getUrl('wishlist/links')?>">
//My cart URL
<?php echo $this->getUrl('checkout/cart')?>">
@wcodex
wcodex / form.mini.phtml
Created October 3, 2013 05:11
How to add and customize the search box in Magento
//Available at [your-theme]/template/categorysearch/form.mini.phtml
<?php
$catalogSearchHelper = $this->helper('catalogsearch');
?>
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div class="form-search">
<div class="container">
<input id="search" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="blink" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" />
</div>
<button type="submit" title="<?php echo $this->__('Search') ?>" class="search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>
@wcodex
wcodex / gist:6805307
Created October 3, 2013 05:14
How to get all Categories in Magento
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?> <?php if (count($_categories) > 0): ?>
<ul> <?php foreach($_categories as $_category): ?>
<li> <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<span><?php echo $_category->getName() ?> </span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
@wcodex
wcodex / gist:6805316
Created October 3, 2013 05:15
How to get current category in Magento
<?php
$_current_category=$this->getCurrentCategory();
echo $_current_category;
?>
@wcodex
wcodex / gist:6807149
Created October 3, 2013 08:52
How to get cart URL and Cart Item Count in Magento
<?php
// to get cart URL
$cartUrl = $this->getUrl('checkout/cart');
//to get cart Item count
$_cartQty = Mage::getSingleton('checkout/cart')->getItemsCount();
?>
@wcodex
wcodex / gist:6807175
Created October 3, 2013 08:55
How to get the welcome message in Magento
<?php
<p class="welcome-msg"><?php echo $this->getWelcome() ?>
?>