How To Limit Posts Per Page On Search
Using the following snippet, you will be able to limit posts per page on search.
1 2 3 4 5 6 |
function limit_posts_per_search_page() { if ( is_search() ) set_query_var('posts_per_archive_page', 20); } add_filter('pre_get_posts', 'limit_posts_per_search_page'); |
Snippet Source/Credit: WordPress.org
How To Display The Number Of Results In WordPress Search
Using the following snippet, you will be able to display the number of results in WordPress search.
1 |
<h2 class="pagetitle">Search Results</h2> |
Now, simply replace it with to:
1 2 3 4 5 6 7 8 9 |
<h2 class="pagetitle">Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2> |
Snippet Source/Credit: ProBlogDesign
How To Log-in A WordPress User Programmatically
Using the following snippet, you will be able to log-in a WordPress user programmatically.
1 2 3 4 5 6 7 8 9 10 |
function auto_login( $user ) { $username = $user; if ( !is_user_logged_in() ) { $user = get_userdatabylogin( $username ); $user_id = $user->ID; wp_set_current_user( $user_id, $user_login ); wp_set_auth_cookie( $user_id ); do_action( 'wp_login', $user_login ); } } |
Once done, now to log-in a user, just simply do the following:
1 |
auto_login( 'admin' ) |
Snippet Source/Credit: emoticode
How To Create A Pinterest ‘Pin It’ Button For Your Blog
Using the following snippet, you will be able to create a Pinterest “Pin It” button for your blog.
1 |
<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a> |
Once done, open your footer.php file and add the Pinterest JavaScript code:
1 |
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script> |
Snippet source/Credit: MarketingTechBlog