Skip to content

Instantly share code, notes, and snippets.

@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
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 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_0
Created August 18, 2014 13:56
Change all spaces wallpaper at once - OSX mac
-- Adapted from http://movingparts.net/2012/09/25/changing-backgroundwallpaper-on-os-x-with-multiple-spaces-and-multiple-monitors/
-- Copied from http://apple.stackexchange.com/questions/61677/changing-desktop-background-in-os-x-10-8-only-changes-it-for-the-current-desktop
-- pick a new background image
set theFile to choose file
-- *Note*: Set the number of spaces/desktops manually
set numSpaces to 12
-- Loop through the spaces/desktops, setting each of their backgrounds in turn:
@arioch1984
arioch1984 / new_gist_file.php
Created July 15, 2014 09:33
Relative to absolute path
function make_absolute($url, $base)
{
// Return base if no url
if( ! $url) return $base;
// Return if already absolute URL
if(parse_url($url, PHP_URL_SCHEME) != '') return $url;
// Urls only containing query or anchor
if($url[0] == '#' || $url[0] == '?') return $base.$url;
@arioch1984
arioch1984 / new_gist_file.php
Created June 20, 2014 12:47
List all hooked WordPress functions
<?php
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
}
@arioch1984
arioch1984 / 0_reuse_code.js
Created May 22, 2014 12:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@arioch1984
arioch1984 / wp_remove_filter_after_first_usage
Created May 22, 2014 12:45
WP remove filter after first usage
//Taken from http://stackoverflow.com/questions/18206115/how-to-avoid-affecting-other-queries-when-using-posts-orderby
// My list of post IDs in my custom order
$my_post_ids = array(1,3,2);
// Apply filter to the ORDERBY SQL statement
add_filter('posts_orderby', 'my_custom_orderby');
function my_custom_orderby($orderby_statement) {
// Disable this filter for future queries!
@arioch1984
arioch1984 / jquery_floating_share_box
Created May 20, 2014 10:07
jQuery floating share box
//Taken from http://www.webanddesigners.com/floating-share-box/
$(function() {
var offset = $("#box").offset();
var topPadding = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
$("#box").stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
@arioch1984
arioch1984 / log_wp_user_programmatically
Last active August 29, 2015 14:01
Log in a WordPress user programmatically
/*
* Taken from http://www.wprecipes.com/log-in-a-wordpress-user-programmatically
*/
<?php
function auto_login( $user ) {
$username = $user;
if ( !is_user_logged_in() ) {
$user = get_userdatabylogin( $username );
$user_id = $user->ID;
wp_set_current_user( $user_id, $user_login );