Exclude wordpress posts or pages from search results

December 23, 2008

Would you like to be able to control which post or pages must be exclued from searches on your WordPress blog? If yes, this article will probably help you a lot. To achieve this, just simply paste the following code on the functions.php file from your theme. In this example, your wordpress posts with IDs 1 and 10 will be excluded from your wordpress blog’s search results: function SearchFilter($query) { if ($query->is_search) { $query->set('cat','1,10'); } return $query; } add_filter('pre_get_posts','SearchFilter');  Read More →

Get wordpress posts having a specific custom field

December 23, 2008

How we can only get posts that have a certain custom field. As far as we know, this question has been asked many times on several blogs and WordPress forums. It is quite simple. What I’ve done is simply using a normal loop (That you can enhance with query_post() for exemple) and then, using a conditional instruction to check out if the post have the esired custom field. <?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("img"); if (isset($customField[0]))... [Read the full story]

Add shortcodes in wordpress sidebar Widgets

December 18, 2008

To allow shortcodes in wordpress sidebar widgets, simply edit the functions.php file from your them and add the following code: add_filter('widget_text', 'do_shortcode'); Once you saved the file, you can now add as many shortcodes as you want in wordpress sidebar widgets.  Read More →

Display the number of comments on each wordpress post

December 16, 2008

How we can display the number of comments for each posts? While some themes do it by default, most of them don’t display it at all. To solve this problem, simply open your index.php file and paste the following code within the loop: <?php comments_number('No comments yet','1 comment','% comments')?> Even better, following code have a link to jump directly to the comments: <a href="<?php the_permalink() ?>#comments"><?php comments_number('No comments yet','1 comment','% comments')?></a>  Read More →

Use WordPress shortcodes with attributes

December 16, 2008

Do you know that WordPress shortcodes can handles attributes? Adding attributes to your shortcodes isn’t that hard. First, make sure that you have read and understand about creating shortcodes. Enclosing shortcodes support attributes in the same way as self-closing shortcodes. Here’s an example of the caption_shortcode() improved to support a ‘class’ attribute, Paste the following code on the functions.php file from your theme. function caption_shortcode( $atts, $content = null ) {    extract( shortcode_atts(... [Read the full story]

Page 3 of 7«12345»...Last »