Tagged: post RSS

  • Jay Kwong 7:28 am on January 19, 2010 Permalink | Reply
    Tags: , post, Shortcode, the loop   

    Shortcode – Display the loop 

    function.php

    function myLoop($atts, $content = null) {
    	extract(shortcode_atts(array(
    		"pagination" => 'true',
    		"query" => '',
    		"category" => '',
    	), $atts));
    	global $wp_query,$paged,$post;
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	if($pagination == 'true'){
    		$query .= '&paged='.$paged;
    	}
    	if(!empty($category)){
    		$query .= '&category_name='.$category;
    	}
    	if(!empty($query)){
    		$query .= $query;
    	}
    	$wp_query->query($query);
    	ob_start();
    	?>
    	<h2><?php echo $category; ?></h2>
    	<ul class="loop">
    	<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo $thumbnail_image; the_title(); ?></a></li>
    	<?php endwhile; ?>
    	</ul>
    	<?php if(pagination == 'true'){ ?>
    	<div class="navigation">
    	  <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
    	  <div class="alignright"><?php next_posts_link('More »') ?></div>
    	</div>
    	<?php } ?>
    	<?php $wp_query = null; $wp_query = $temp;
    	$content = ob_get_contents();
    	ob_end_clean();
    	return $content;
    }
    add_shortcode("loop", "myLoop");
    

    display a loop :

    [loop category="news" query="" pagination="false"]
    

    http://www.wprecipes.com/

     
  • Jay Kwong 7:08 am on January 19, 2010 Permalink | Reply
    Tags: images, post, ,   

    Automatically resize post pictures 

    First, note that this code use TimThumb to resize pictures. This recipe explain how to install TimThumb on your WordPress blog.

    Let’s start by creating the shortcode. Just paste the code below into your functions.php file.

    function imageresizer( $atts, $content = null ) {
    	return '<img src="/timthumb/timthumb.php?src='.$content.'&w=590" alt="" />';
    }
    
    add_shortcode('img', 'imageresizer');
    

    Then, you can use the following syntax to add an automatically resized image to your blog post:

    [img]http://www.yoursite.com/yourimage.jpg[/img]
    
     
  • Jay Kwong 6:57 am on January 19, 2010 Permalink | Reply
    Tags: attachments, post,   

    Show WordPress post attachments 

    To achieve this recipe, just paste the following code anywhere in your post.php file and attachments will be displayed.

    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => null,
    	'post_status' => null,
    	'post_parent' => $post->ID
    );
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    		echo apply_filters('the_title', $attachment->post_title);
    		the_attachment_link($attachment->ID, false);
    	}
    }
    
     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel