Skip to content

Instantly share code, notes, and snippets.

View mukundthanki's full-sized avatar
🎯
Focusing

Mukund Thanki mukundthanki

🎯
Focusing
View GitHub Profile
@mukundthanki
mukundthanki / functions.php
Last active March 26, 2018 06:27
WordPress: Insert multiple files and attach them to post from front-end.
<?php
# Upload multiple files and attach them to post using single function
// Files Uploader attach to shop
if ($_FILES) {
$files = $_FILES['shop-imgs'];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
@mukundthanki
mukundthanki / google-map-v3.js
Last active December 14, 2015 23:48
Google map v3
// JavaScript Document
function initialize() {
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById("map_canvas"),
@mukundthanki
mukundthanki / template.phtml
Last active December 14, 2015 04:29
Magento: Load selected categories in magento
<?php
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addAttributeToSelect('*');
$categories->addAttributeToFilter('is_active', 1);
$categories->addAttributeToFilter('entity_id', array('in' => array(3,4,5,6,7)));// Loading selected categories by passing array
$categories->load();
// Normal list of categories
if($categories){
echo "<ul>";
@mukundthanki
mukundthanki / list.phtml
Last active December 14, 2015 04:28
Magento: Load products from selected categories in magento
<?php
$categories = array(8,22);
$collection = mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',1)
->joinField('category_id',
'catalog/category_product',
'category_id',
'product_id=entity_id',
null,
@mukundthanki
mukundthanki / My Magento Code.php
Last active May 31, 2018 09:24 — forked from claudiu-marginean/My Magento Code.php
Magento: Code Snippets
<block type="cms/block" name="block_name">
<action method="setBlockId"><id>block_code</id></action>
</block>
{{block type="cms/block" block_id="block_code"}}
{{block type="catalog/product_list" category_id="79" template="catalog/product/list_random.phtml"}}
@mukundthanki
mukundthanki / view.phtml
Last active October 12, 2015 06:28
Magento: Using Helper Classes in Magento
<?php
// Get resized Image on list page.( Mage_Catalog_Block_Product_List )
echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(149);
// Get attribute
$_helper = $this->helper('catalog/output');
echo $_helper->productAttribute($_product, $_product->getName() , 'name');
?>
@mukundthanki
mukundthanki / col-left.phtml
Last active September 23, 2019 14:09
Magento: How to get current category in magento
<?php
// Using singleton
$_category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
// Using Model
$_category = Mage::getModel('catalog/layer')->getCurrentCategory();
// Using Registry
$_category = Mage::registry('current_category');
?>
@mukundthanki
mukundthanki / gist:3985015
Created October 31, 2012 05:32
Limit Words To String( title, content, anything )
<?php
function string_limit_words($string, $word_limit){
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
//Usage
//Suppose for wordpress content/excerpt length