Skip to content

Instantly share code, notes, and snippets.

View pigmentGit's full-sized avatar

pigmentGit pigmentGit

View GitHub Profile
@pigmentGit
pigmentGit / Get current page and set class worpdress
Created April 16, 2015 23:24
Shows current page and displey some class to be used
<?php if ( is_home() || is_single() || is_search() || is_archive() ) { echo 'current_page_item'; } ?>"
@pigmentGit
pigmentGit / gist:00fc249c2bc0a0ce00f4
Created March 1, 2015 16:01
Show / Hide submenu on click with sompel jQuery
// show sort submenu on click in phone / table
$(".hasChild").click(function() {
if($(this).hasClass('showUl')) {
$('.hasChild').removeClass('showUl');
$(this).removeClass('showUl');
} else {
$('.hasChild').removeClass('showUl');
$(this).addClass('showUl');
@pigmentGit
pigmentGit / gist:bd328e17864d574901d3
Created February 28, 2015 16:28
Use for Typekit embedded
(function(d) {
var tkTimeout=3000;
if(window.sessionStorage){if(sessionStorage.getItem('useTypekit')==='false'){tkTimeout=0;}}
var config = {
kitId: 'a1b2c3f4',
scriptTimeout: tkTimeout
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+"wf-inactive";if(window.sessionStorage){sessionStorage.setItem("useTypekit","false")}},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+="wf-loading";tk.src='//use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
@pigmentGit
pigmentGit / gist:9bcad1c3830213c19e51
Created February 23, 2015 12:52
Pagination custom post types custom page template
<!-- Loop -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array(
'post_type' => 'aktuellt',
'posts_per_page' => 3,
'paged' => $paged,
);
query_posts($args); while ( have_posts() ) : the_post(); ?>
@pigmentGit
pigmentGit / gist:24cbe067e66d9014f158
Created February 4, 2015 14:39
Remove link to images when inserting in wisywig editor
function wpb_imagelink_setup() {
$image_set = get_option( 'image_default_link_type' );
if ($image_set !== 'none') {
update_option('image_default_link_type', 'none');
}
}
add_action('admin_init', 'wpb_imagelink_setup', 10);
@pigmentGit
pigmentGit / gist:a6ab9818e2b218e0721c
Created November 27, 2014 07:52
Styra excerpt unikt för varje gång
//Styra längd på excerpt
function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = $excerpt.'...';
return $excerpt;
}
@pigmentGit
pigmentGit / gist:2e7ab03c5b3a73dfcebf
Created November 27, 2014 07:50
Bestämma maxlängd för custom_field
<?php $trim_length = 120; //desired length of text to display
$custom_field = 'om_omrade';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
echo rtrim(substr($value,0,$trim_length)) . '...';
}
?>
@pigmentGit
pigmentGit / gist:ff5666bc4e830255387a
Created November 27, 2014 07:48
Bestämma maxlängd för the_title
<?php if (strlen($post->post_title) > 25) { echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...'; } else { the_title();} ?>
@pigmentGit
pigmentGit / gist:2390eea2c10d90dd8daa
Created November 27, 2014 07:46
Lista kategorier som är "child of" en speciell kategori
<?php
$args = array(
'orderby' => 'name',
'child_of' => 12
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a></li>' ;
}
@pigmentGit
pigmentGit / gist:bf474737810ad3e228bf
Created November 27, 2014 07:44
Lägg till class på aktiv kategori i kategorilista
// add class to active cat
function tax_cat_active( $output, $args ) {
if(is_single()){
global $post;
$terms = get_the_terms( $post->ID, $args['taxonomy'] );
foreach( $terms as $term )
if ( preg_match( '#cat-item-' . $term ->term_id . '#', $output ) )
$output = str_replace('cat-item-'.$term ->term_id, 'cat-item-'.$term ->term_id . ' current-cat', $output);