Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • Jay Kwong 9:48 am on February 17, 2010 Permalink | Reply
    Tags: search,   

    Highlight Search Terms in Results 

    In an attempt to make your WordPress search even more user friendly, you can highlight the search terms in the results. We did this for one of our clients, so we thought it would be useful for other users. In this article we will show you how you can highlight search terms in the results in WordPress.

    First open your search.php and look for the following code:

    <?php the_title(); ?>

    Replace the above code with:

    <?php echo $title; ?>

    Make sure that you paste this line above the title code:

    <?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title); ?>
    

    Now open your CSS file and add the styling for the class search-excerpt, and it will highlight the term. Currently the code is making the search terms bold.

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

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

    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