Skip to content

Instantly share code, notes, and snippets.

@arioch1984
arioch1984 / new_gist_file.php
Created September 16, 2014 14:50
Function for remove get variables from url
<?php
//Remove get variables from url
function removeqsvar($url, $varname) {
return preg_replace('/([?&])'.$varname.'=[^&]+(&|$)/','$1',$url);
}
?>
@arioch1984
arioch1984 / new_gist_file.php
Created October 14, 2014 13:20
Filter posts per page
<?php
function my_custom_posts_per_page($query){
$query->query_vars['posts_per_page'] = 3;
}
add_filter( 'pre_get_posts', 'my_custom_posts_per_page' );
?>
@arioch1984
arioch1984 / new_gist_file.php
Created October 24, 2014 10:08
get an array of all categories with details in Magento
<?php
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToFilter('level',2)
->addAttributeToSelect('is_active');
foreach ($categories as $category)
@arioch1984
arioch1984 / new_gist_file.php
Last active August 29, 2015 14:10
Programmatically create category
<?php
try{
$category = Mage::getModel('catalog/category');
$category->setName('check');
$category->setUrlKey('new-category');
$category->setIsActive(1);
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor(1); //for active achor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
@arioch1984
arioch1984 / max-from-associative-array-column.php
Last active August 29, 2015 14:11
max value from a column of associative array
<?php
function array_col(array $a, $x)
{
return array_map(function($a) use ($x) { return $a[$x]; }, $a);
}
$max = max(array_col($menu_items, 'colonna'));
?>
@arioch1984
arioch1984 / get-column-from-associative.php
Created December 12, 2014 14:30
Get column from associative array
<?php
function array_col(array $a, $x)
{
return array_map(function($a) use ($x) { return $a[$x]; }, $a);
}
?>
@arioch1984
arioch1984 / wp-menu-dynamic-links.php
Created December 12, 2014 15:33
add dynamic links to wordpress menu voice urls
@arioch1984
arioch1984 / cpt-field-change-from-child-theme-1.php
Last active August 29, 2015 14:11
Wordpress: Change CPT values from child theme
<?php
add_action('registered_post_type', 'custom_registered_post_type_handler', 10, 2);
function custom_registered_post_type_handler($post_type, $args) {
do_action("custom_registered_{$post_type}_post_type", $post_type, $args);
}
add_action('custom_registered_foo_post_type', 'custom_registered_foo_post_type_handler', 10, 2);
function custom_registered_foo_post_type_handler($post_type, $args) {
remove_action(current_filter(), __FUNCTION__, 10, 2); // only run once
// change your args here
@arioch1984
arioch1984 / wp-print-hooks.php
Created January 22, 2015 10:51
Wordpress: Print hooks
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if ($_GET['instrument']=='hooks') {
@arioch1984
arioch1984 / scroll-to-anchor.js
Created February 13, 2015 10:21
JS - Scroll to anchor
function scrollToAnchor(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
}
scrollToAnchor('id3');