Paged WP_query (That works!)

<?php // set up or arguments for our custom query $paged = ( get_query_var(’paged’) ) ? get_query_var(’paged’) : 1; $query_args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘tutorials’, ‘posts_per_page’ => 5, ‘paged’ => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); ?>   <?php if ( $the_query->have_posts() )… Continue reading Paged WP_query (That works!)

Embed a PDF in an iframe

This is definitely the easiest way to display a PDF file on your website: The PDF is loaded through Google docs and then displayed in an iframe, on your own site. To use this shortcode, first paste the code below into your functions.php file:   function cwc_viewpdf($attr, $url) { return ‘<iframe src="http://docs.google.com/viewer?url=’ . $url .… Continue reading Embed a PDF in an iframe

Members only content

If you want to create some private content that only registered users are able to see, the following shortcode is the solution to your problem. Paste the code below into your functions.php file in order to create the shortcode:   function cwc_member_check_shortcode( $atts, $content = null ) { if ( is_user_logged_in() && !is_null( $content )… Continue reading Members only content

Improved Excerpt

function improved_trim_excerpt( $text ) { if ( ” == $text ) { $permalink = get_permalink(); // my addition $text = get_the_content( ” ); $text = strip_shortcodes( $text ); $text = apply_filters( ‘the_content’, $text ); $text = preg_replace( ‘@<script[^>]*?> . *?</script>@si’, ”, $text ); $text = str_replace( ‘]]>’, ‘]]>’, $text ); $text = strip_tags( $text, ‘<b><em><i><p><strong><sub><sup><a>’… Continue reading Improved Excerpt

Get the image plugin

Usage: <?php get_the_image( array( ‘default_image’ => ‘http://mysite.com/wp-content/uploads/example.jpg’ ) ); ?> Parameters: $defaults = array( ‘meta_key’ => array( ‘Thumbnail’, ‘thumbnail’ ), ‘post_id’ => $post->ID, ‘attachment’ => true, ‘the_post_thumbnail’ => true, ‘size’ => ‘thumbnail’, ‘default_image’ => false, ‘order_of_image’ => 1, ‘link_to_post’ => true, ‘image_class’ => false, ‘image_scan’ => false, ‘width’ => false, ‘height’ => false, ‘format’ =>… Continue reading Get the image plugin

Related posts

<?php //Gets category info global $wp_query; $cats = get_the_category(); $tempQuery = $wp_query; $currentId = $post->ID;   //related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "posts_per_page=6&orderby=rand&cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count =… Continue reading Related posts

Random Post list

<ul> <?php $args = array( ‘numberposts’ => 5, ‘orderby’ => ‘rand’ ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>

List of Posts

Simple list: <ul> <?php global $post; $args = array( ‘numberposts’ => 5, ‘offset’=> 1, ‘category’ => 1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> All post data: <?php $args = array( ‘numberposts’ => 3 ); $lastposts = get_posts(… Continue reading List of Posts

Display tags in 3 columns

<?php $tags = get_terms(’post_tag’); $groups = array(’name__like’ => "a", ‘order’ => ‘ASC’); $tags_count = count($tags); $count = intval( $tags->count ); $percolumn = ceil($tags_count / 3);   for ($i = 0;$i < $tags_count;$i++): if ($i < $percolumn): $tag_left .= ‘ <li><a href="’. get_tag_link($tags[$i]->term_id) . ‘"rel="tag">’ . $tags[$i]->name .’ (‘ . $tags[$i]->count . ‘)</a></li> ‘ . "\n";… Continue reading Display tags in 3 columns