Tagged: Content RSS

  • Jay Kwong 7:28 am on January 19, 2010 Permalink | Reply
    Tags: Content, , 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 6:42 am on January 19, 2010 Permalink | Reply
    Tags: Content,   

    Content in two columns 

    This code is poweful but definitely easy to implement. Just paste it on your functions.php file and it will automatically output your post content in columns.
    Your post content will be splitted on tags.

    functions.php

    function my_multi_col($content){
    $columns = explode('</h2>
    <h2>', $content);
    
    $i = 0;
    
    foreach ($columns as $column){
    if (($i % 2) == 0){
    $return .= '
    <div class="content_left">' . "\n";
    if ($i &gt; 1){
    $return .= "
    <h2>";
    } else{
    $return .= '
    <div class="content_right">
    
    ' . "\n
    <h2>";
    }
    $return .= $column;
    $return .= '</h2>
    </div>
    ';
    $i++;
    }
    
    if(isset($columns[1])){
    $content = wpautop($return);
    }else{
    $content = wpautop($content);
    }
    echo $content;
    }
    }
    add_filter('the_content', 'my_multi_col');</h2>
    </div></h2>
    

    CSS

    .content_right, .content_left{ float:left; width:45%; }
    .content_left{ padding-right:5%; }
    

    http://www.wprecipes.com/

     
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