Public snipts »
depi's
snipts
showing 1-17 of 17 snipts
-
∞ Returns the number of results
<?php echo $wp_query->found_posts; ?>
-
∞ Returns the searched keyword
<?php echo get_search_query(); ?>
-
∞ Return a class is a certain page template is used
<?php function page_template_class() { $page_template_class = ''; if (is_page_template('kinderen.php')) { $page_template_class = 'kinderen'; } if (!empty($page_template_class)) { echo ' class="'.$page_template_class.'"'; } else { return false; } } ?>
-
∞ Replace the output of wp_list_pages();
<?php $page_output = wp_list_pages('echo=0&title_li=&sort_column=menu_order&depth=1&include='.$page_ids); $page_output = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', $page_output); echo $page_output; ?>
-
∞ Get the nth sentence from the post (beta)
<?php function the_nth_sentence($sentence_num = 1) { if ($sentence_num == 0) { return false; } if ($sentence_num >= 1) { $sentence_num = $sentence_num-1; } $content = get_the_content('',FALSE,''); $content = apply_filters('the_content', $content); $content = strip_tags($content); $pos = strpos($content, '.'); for($i=1; $i<=$sentence_num; $i++) { $pos = strpos($content, '.', $pos+1); } echo '<p>' . substr($content,0,$pos+1) . '</p>'; } ?>
-
∞ Get the first sentence of the post
<?php function the_first_sentence() { $content = get_the_content('',FALSE,''); $content = apply_filters('the_content', $content); $content = strip_tags($content); $pos = strpos($content, '.'); echo '<p>' . substr($content,0,$pos+1) . '</p>'; } ?>
-
∞ Exclude array of categories
<?php function exclude_categories(array $categories, $sign = TRUE) { $exclude_cat = new WP_Query('showposts=0'); if ($sign == TRUE): $sign = "-"; else: $sign = ""; endif; foreach((get_categories()) as $cat): if(in_array($cat->cat_name, $categories)): $exclude_id .= $sign . $cat->cat_ID .','; endif; endforeach; $exclude_id = substr($exclude_id, 0, -1); return $exclude_id; } ?>
-
∞ Display only "sticky posts"
<?php $sticky = new WP_Query(array("post__in" =>get_option("sticky_posts"))); ?>
-
∞ Get permalink to a page by id
<?php echo get_permalink(get_page_id('articles')); ?>
-
∞ Get the slug of the current post/page
<?php echo $post->post_name; // the $post array also contains other useful/interesting data ?>
-
∞ Alternative replacement for the_content(); - it show a first <p> from a post (place in functions.php)
<?php function the_summary() { $content = get_the_content('',FALSE,''); $content = apply_filters('the_content', $content); $pos = strpos($content, '</p>'); echo substr($content,0,$pos+4); } ?>
-
∞ Get category ID
<?php get_cat_id('categoryName'); ?>
-
∞ Get $post_category_id
<?php foreach(get_the_category() as $category) { $post_category_id = $category->cat_ID; } ?>
-
∞ getTopParentPostTitle
<?php function getTopParentPostTitle($myid){ $mypage = get_page($myid); if ($mypage->post_parent == 0){ return $mypage->post_title; } else{ return getTopParentPostName($mypage->post_parent); } } ?>
-
∞ getTopParentPostName
<?php function getTopParentPostName($myid){ $mypage = get_page($myid); if ($mypage->post_parent == 0){ return $mypage->post_name; } else{ return getTopParentPostName($mypage->post_parent); } } ?>
-
∞ Yahoo CSS Reset
/* YUI CSS RESET */ body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img { border:0; } address,caption,cite,code,dfn,em,strong,th,var { font-style:normal; font-weight:normal; } ol,ul { list-style:none; } caption,th { text-align:left; } h1,h2,h3,h4,h5,h6 { font-size:100%; font-weight:normal; } q:before,q:after { content:''; } abbr,acronym { border:0; }
-
∞ get_page_id
<?php function get_page_id($page_name){ global $wpdb; $page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page'"); return $page_name; } ?>



CSS Pocket Reference: Visual Presentation for the Web