Skip to content

Instantly share code, notes, and snippets.

View jbutko's full-sized avatar

Jozef Butko jbutko

View GitHub Profile
@jbutko
jbutko / scripts.js
Created February 25, 2014 19:27
jQuery: Scroll to ID element
$('a[href*=#]').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 700, 'linear');
return false;
});
@jbutko
jbutko / _mixins.scss
Created March 20, 2014 20:09
CSS, SASS: em mixin
/* PX to EM conversion
example: font-size: em(30);
*/
@function em($target, $context: 16) {
@return ($target / $context) * 1em;
}
@jbutko
jbutko / index.php
Created March 25, 2014 19:45
WP, CCPM: Nezobrazovanie prazdnych poli
<div class="entry-content">
<?php the_post_thumbnail(); ?>
<?php if (get_custom_field('subtitulo')):?>
<p class="evento-subtitulo"><?php print_custom_field('subtitulo'); ?></p>
<?php endif;?>
<?php if (get_custom_field('fecha_inicio')):?>
<p><strong>Fecha:</strong> <?php print_custom_field('fecha_inicio'); ?><?php echo get_custom_field('fecha_fin') ? ' hasta el '.get_custom_field('fecha_fin') :''; ?></p>
<?php endif;?>
<?php if (get_custom_field('lugar')):?>
@jbutko
jbutko / index.php
Created March 26, 2014 17:09
WP, functions.php: Add non-clickable images to post
update_option( 'image_default_link_type', 'none' );
function no_atag_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); }
add_filter('the_content', 'no_atag_on_images');
// From http://freakify.com/make-wordpress-images-non-clickable-inside-a-post/
@jbutko
jbutko / scripts.js
Created March 29, 2014 13:13
jQuery: jQuery add and remove class on a menu/nav
$(function(){
$(".navtab>li").click(function(){
$(this).addClass('selected').siblings().removeClass('selected');
});
});
// From http://stackoverflow.com/questions/12606784/jquery-add-and-remove-class-on-a-menu
@jbutko
jbutko / index.php
Created March 29, 2014 19:41
WP: Get pount position in total post count
$numposts = wp_count_posts('post');
echo $numposts->publish;
// From http://wordpress.org/support/topic/get-pount-position-in-total-post-count?replies=5
@jbutko
jbutko / index.php
Created March 29, 2014 19:45
WP, single.php: Post X of Y in single.php / Post Counter
class MY_Post_Numbers {
private $count = 0;
private $posts = array();
public function display_count() {
$this->init(); // prevent unnecessary queries
$id = get_the_ID();
echo sprintf( '<div class="post-counter">Post number<span class="num">%s</span><span class="slash">/</span><span class="total">%s</span></div>', $this->posts[$id], $this->count );
}
@jbutko
jbutko / scripts.js
Created April 5, 2014 20:58
javaScript: Get position in viewport coordinates
element.getBoundingClientRect(); // Get position in viewport coordinates
// From http://stackoverflow.com/questions/1567327/using-jquery-to-get-elements-position-relative-to-viewport
@jbutko
jbutko / index.php
Created April 6, 2014 10:32
WP, wp-admin: Add admin favicon
function pa_admin_area_favicon() {
echo '<link rel="shortcut icon" href="http://cdn.alex.leonard.ie/favicon.ico" />';
}
add_action('admin_head', 'pa_admin_area_favicon');
// From http://alex.leonard.ie/2012/05/24/wordpress-admin-area-favicon/
@jbutko
jbutko / styles.scss
Created April 10, 2014 17:35
SASS, SCSS, CSS: Select all elements on the same node level
.second {
.first ~ & {
/* styles to be applied to .second if a .first exists at the same node level */
}
}
// From http://stackoverflow.com/questions/15246387/css-and-or-sass-sibling-selector-upwards