Skip to content

Instantly share code, notes, and snippets.

View mrfoxtalbot's full-sized avatar

Alvaro Gómez Velasco mrfoxtalbot

View GitHub Profile
add_filter('body_class','mrfx_add_category_to_single');
function mrfx_add_category_to_single($classes, $class) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug to the $classes array
$classes[] = $category->category_nicename;
}
}
// return the $classes array
@mrfoxtalbot
mrfoxtalbot / gist:5f92ae791dd4c4e26ccd
Last active January 25, 2016 15:58
WordPress shortcode to display a category description?
Try this. Add the code below to your functions.php file -
<? add_shortcode('cat_description', 'my_cat_description_shortcode');
function my_cat_description_shortcode($atts){
$a = shortcode_atts( array(
'id' => 0,
), $atts );
return category_description($a['id']);
@mrfoxtalbot
mrfoxtalbot / selector.js
Created January 25, 2016 21:14
Vainilla JS add CSS class
<script>
var element = document.querySelector("#docentes .fusion-column");
element.onPress.className += " activo";
</script>
@mrfoxtalbot
mrfoxtalbot / loop-shortcode.php
Created February 1, 2016 09:04
WordPress shortcode to loop through child
<?
add_image_size( 'areas', 400, 300, true );
add_shortcode( 'areas', 'custom_query_shortcode' );
function custom_query_shortcode( $atts ) {
// EXAMPLE USAGE:
// [areas show_posts="100" post_type="page" post_parent="246"]
// Defaults
$defaults = array(
function twentyfourteen_list_authors() {
$contributor_ids = get_users( array(
'fields' => 'ID',
// 'orderby' => 'post_count', // WPCOM disabled, see #2023-wpcom-themes
'order' => 'DESC',
'who' => 'authors',
) );
foreach ( $contributor_ids as $contributor_id ) :
$post_count = count_user_posts( $contributor_id );
@mrfoxtalbot
mrfoxtalbot / gist:f7553c0d0ebb4eee8d72
Last active February 12, 2016 08:22
Ejemplo de un Toggle encapsulado
jQuery( document ).ready(function($) {
$( "#someid p" ).click(function() {
$( this ).toggleClass( "activo" );
});
;});
@mrfoxtalbot
mrfoxtalbot / douchebag-vertical-align.scss
Last active February 14, 2016 02:33
Alinear en vertical. Heterodoxo pero funciona. Como mixin mola mil.
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
/* As a mixin */
@mixin centerer {
position: absolute;
top: 50%;
@mrfoxtalbot
mrfoxtalbot / parm-mixin.scss
Created February 14, 2016 02:37
Parámetros en un mixin
@mixin mixinName ($param: 10px) {
line-height: $param;
font-size: $param;
}
// https://css-tricks.com/the-extend-concept/
@mrfoxtalbot
mrfoxtalbot / keep-aspect-ratio-mixin.scss
Created February 14, 2016 03:03
Maintain Aspect Ratio Mixin
@mixin aspect-ratio($width, $height) {
position: relative;
&:before {
display: block;
content: "";
width: 100%;
padding-top: ($height / $width) * 100%;
}
> .content {
position: absolute;
@mrfoxtalbot
mrfoxtalbot / gist:5dbefd3bff58e48f81fa66eae27e359c
Created April 18, 2016 12:48
Get WordPress localization file from child theme
// Load translation files from your child theme instead of the parent theme
function my_child_theme_locale() {
load_child_theme_textdomain( 'total', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_locale' );