sticky
closedShow parent page title regardless of what subpage you are on
<?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
} else {
wp_title('');
}
?>
hide login error messages
add_filter('login_errors',create_function('$a', "return null;"));
Create “Search By Category”
code in sidebar
<form id="searchform" method="get" action="<?php bloginfo('url'); ?>">
<input type="text" name="s" id="s" size="15" />
<?php wp_dropdown_categories('show_option_none=Select category'); ?>
<input type="submit" value="Search" />
</form>
code in functions
add_action('pre_get_posts', 'search_by_cat');
function search_by_cat()
{
global $wp_query;
if (is_search()) {
$cat = intval($_GET['cat']);
$cat = ($cat > 0) ? $cat : '';
$wp_query->query_vars['cat'] = $cat;
}
}
Custom Default Avatar For BuddyPress
code in functions
function myavatar_add_default_avatar( $url )
{
return get_stylesheet_directory_uri() .'/images/myimage.jpg';
}
add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );
Change the Default Avatar
function my_default_get_group_avatar($avatar) {
global $bp, $groups_template;
if( strpos($avatar,'group-avatars') ) {
return $avatar;
}
else {
$custom_avatar = get_stylesheet_directory_uri() .'/images/myimage.jpg';
if($bp->current_action == "")
return 'group->name ) . '" />';
else
return 'group->name ) . '" />';
}
}
add_filter( 'bp_get_group_avatar', 'my_default_get_group_avatar');
Highlight Current Category Menu Item
code in functions
function sgr_show_current_cat_on_single($output) {
global $post;
if( is_single() ) {
$categories = wp_get_post_categories($post->ID);
foreach( $categories as $catid ) {
$cat = get_category($catid);
// Find cat-item-ID in the string
if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
$output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . ' current-cat', $output);
}
}
}
return $output;
}
add_filter('wp_list_categories', 'sgr_show_current_cat_on_single');
Display Custom Message
<?php if(isset($_COOKIE['comment_author_'.COOKIEHASH])) {
$lastCommenter = $_COOKIE['comment_author_'.COOKIEHASH];
echo "Welcome Back ". $lastCommenter ."!";
} else {
echo "Welcome, Guest!";
} ?>
Display Recently Updated Posts
<?php
$today = current_time('mysql', 1);
$number = 5; // number of posts
if($recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $number")):
?>
<h2><?php _e("Recently Updated"); ?></h2>
< ul>
<?php
foreach($recentposts as $post) {
if($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo '< li>< a href="'.get_permalink($post->ID).'">'.the_title().'</ a></ li>';
} ?>
</ ul>
<?php endif; ?>
Display Content to Search Engine Visitors
functions:
<?php function scratch99_fromasearchengine() {
$ref = $_SERVER['HTTP_REFERER'];
$SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
foreach($SE as $source) {
if(strpos($ref, $source) !== false) return true;
}
return false;
} ?>
template
<?php if(function_exists('scratch99_fromasearchengine')) {
if (scratch99_fromasearchengine()) {
// INSERT YOUR CODE HERE
}
} ?>
This topic has been closed to new replies.