<?php /* Template Name: Login Template */ ?> <?php global $user_ID; //if (!$user_ID) { if($_POST){ //We shall SQL escape all inputs $username = $wpdb->escape($_REQUEST['username']); $password = $wpdb->escape($_REQUEST['password']); $remember = $wpdb->escape($_REQUEST['rememberme']); if($remember) $remember = "true"; else $remember = "false"; $login_data = array(); $login_data['user_login'] = $username; $login_data['user_password'] = $password; $login_data['remember'] = $remember; $user_verify = wp_signon( $login_data, true ); if ( is_wp_error($user_verify) ) { echo "<span class='error loginfind'>Invalid username or password. Please try again!</span>"; exit(); } else { echo "<script type='text/javascript'>window.location='". get_bloginfo('url') ."'</script>"; exit(); } } else { get_header(); ?> <div id="content"> <div> <?php if(!is_user_logged_in()) { ?> <div> Welcome ! </div> <div id="result"></div> <form id="wp_login_form" name="login" method="post" action=""> <input type="hidden" name="action" value="login" /> <input type="hidden" name="redirect_to" value="<?php echo get_option('home'); ?>" /> <div> <ul> <li>Username:<br/><input type="text" name="username" id="log" value="" /></li> <li>Password:<br/><input type="password" name="password" id="pwd" /></li> <li><input id="submitbtn" type="submit" value="Login"/><br/> <a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword/">Forgot password</a> </div></li> </ul> </form> <div> Dont You Have Account<br/> <input type="button" value="Find Out More!" onclick="window.location.href='<?php echo get_option('home'); ?>/welcome/'" /> </div> <?php } else { global $current_user; get_currentuserinfo(); if($current_user->user_firstname != '' && $current_user->user_lastname) echo "Welcome " . $current_user->user_firstname . "," . $current_user->user_lastname . "!"; else echo "Welcome " . $current_user->user_login . "!"; echo " | <a title='Logout' href='" . wp_logout_url('index.php') . "'>Logout</a><br><br>"; ?> You are currently logged in! <?php } ?> </div> <div> </div> <?php the_content(); ?> <script type="text/javascript"> $("#submitbtn").click(function() { $('#result').html('<img src="<?php bloginfo('template_url'); ?>/images/loader.gif" />').fadeIn(); var input_data = $('#wp_login_form').serialize(); $.ajax({ type: "POST", url: "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>", data: input_data, success: function(msg){ $('.loader').remove(); $('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow'); } }); return false; }); </script> </div> <?php get_footer(); } //} //else //{ //echo "<script type='text/javascript'>window.location='". get_bloginfo('url') ."'</script>"; //} ?>
Category Archives: CMS
Fixing Mail Chimp Plugin Javascript Validation
GOTO plugins/mailchimp/js/mailchimp.js
change line 23
from:
$('#mc_signup_submit').attr("disabled","");
to:
$('#mc_signup_submit').removeAttr("disabled");
Contact Form 7 Phone Number Validation
========================= contact-form-7/modules/text.php
insert this code:
wpcf7_add_shortcode( 'digit', 'wpcf7_text_shortcode_handler', true ); wpcf7_add_shortcode( 'digit*', 'wpcf7_text_shortcode_handler', true );
after this:
wpcf7_add_shortcode( 'email*', 'wpcf7_text_shortcode_handler', true );
insert this code:
if ( 'digit' == $type || 'digit*' == $type ) $class_att .= ' wpcf7-validates-as-digit';
after this:
if ( 'text*' == $type || 'email*' == $type ) $class_att .= ' wpcf7-validates-as-required';
insert this code:
add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 ); add_filter( 'wpcf7_validate_digit*', 'wpcf7_text_validation_filter', 10, 2 );
after this:
add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
insert this code:
if ( 'digit' == $type || 'digit*' == $type ) { if ( '' == $_POST[$name] ) { $result['valid'] = false; //$result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' ); $result['reason'][$name] = wpcf7_get_message( 'invalid_required' ); } elseif ( '' != $_POST[$name] && ! is_telnum( $_POST[$name] ) ) { $result['valid'] = false; //$result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_digit' ); $result['reason'][$name] = wpcf7_get_message( 'invalid_digit' ); } }
after this if code:
if ( 'email' == $type || 'email*' == $type ) { if ( 'email*' == $type && '' == $_POST[$name] ) { $result['valid'] = false; $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' ); } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) { $result['valid'] = false; $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_email' ); } }
================== contact-form-7/includes/functions.php to add the error message for the telephone number validation.
insert this code:
'invalid_digit' => array( 'description' => __( "There is a field that sender is needed to fill in with numbers", 'wpcf7' ), 'default' => __( 'Please fill the required field with numbers.', 'wpcf7' ) )
after this code:
'invalid_required' => array( 'description' => __( "There is a field that sender is needed to fill in", 'wpcf7' ), 'default' => __( 'Please fill the required field.', 'wpcf7' ) ),
===========================wp-includes/formatting.php and create a new function
function is_telnum($telnum) { //$regexp = '/^[0-9\+\-]{7,}$/'; //$regexp = '/^[0-9]{1,}/';//numeric $regexp = '/^[0-9\+\-\)\(\d\s]{7,}$/'; if(preg_match($regexp, $telnum)) return true; else return false; }
=========
Your Phone [digit* text-123]
Free WordPress Plugins List
Below Plugins are some of the free plugins i used in my projects
Contact Form | Contact Form7 |
|
|
Sitemap Plugin | wp-sitemap,simple sitemap(good) |
|
|
Support buddypress in any themes | BuddyPress Template Pack |
|
|
Creating/editing,renaming User roles | role manger(Best) |
|
|
Lightbox image | Lightbox 2 |
|
|
Best Customizing content Slider | Featured articles Lite |
|
|
Twitter Messages | Twitter for WordPress extended |
|
|
Weather Plugin | WPwunderground |
|
|
Ad manager | wp insert |
|
|
Subscription | Subscribe2 |
|
|
youtube Video slider(carousel) | CDOKAY TV |
|
|
Category List In Hierarchical Order inWordpress edit post page(backend) | Category Checklist Tree |
|
|
Video slider with flash | Ultimate carousel free Video Gallery, pluginswp.com To use the slider inside template insert the following code
|
Disable Admin Bar In WordPress Via Code
Goto functions.php in theme directory
if(!current_user_can('administrator')): show_admin_bar(false); endif;
Getting Page/Post ID,Title,Slug,Object
<?php $post_obj = $wp_query->get_queried_object(); $post_ID = $post_obj->ID; $post_title = $post_obj->post_title; $post_slug = $post_obj->post_name; ?>
(or)
<?php global $wpdb; $id= $post->ID; $postparent=$post->post_parent; echo $id; ?>
(or)
<?php ob_start(); $id=the_ID(); $id=ob_get_contents(); ob_end_clean(); echo $id; ?>
Getting All Post In Page With Pagination
functions.php===>
<?php function pagination($pages = '', $range = 4) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>"; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>First</a>"; if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'> << Previous</a>"; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>"; } } if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next >></a>"; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last</a>"; echo "</div>\n"; } } ?>
style.css===>
.pagination { clear:both; padding:20px 0; position:relative; font-size:11px; line-height:13px; } .pagination span, .pagination a { display:block; float:left; margin: 2px 2px 2px 0; padding:6px 9px 5px 9px; text-decoration:none; width:auto; color:#fff; background: #555; } .pagination a:hover{ color:#fff; background: #3279BB; } .pagination .current{ padding:6px 9px 5px 9px; background: #3279BB; color:#fff; }
Template Code(use in index.php)===>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'post', 'posts_per_page' => 10, 'paged' => $paged ,'cat' => '4' ); $wp_query = new WP_Query($args); while ( have_posts() ) : the_post(); ?> <!-- <h2><?php the_title() ?></h2>--><?php get_template_part('post-type/main'); ?> <?php endwhile; ?> <!-- then the pagination links --> <?php next_posts_link( 'Older posts' ); ?> <?php previous_posts_link( 'Newer posts' ); ?> <?php if (function_exists("pagination")) { pagination(); } ?>
Excerpt & Content Limit In WordPress
Add this to functions.php in ur theme directory
function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); return $excerpt; } function content($limit) { $content = explode(' ', get_the_content(), $limit); if (count($content)>=$limit) { array_pop($content); $content = implode(" ",$content).'...'; } else { $content = implode(" ",$content); } $content = preg_replace('/\[.+\]/','', $content); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); return $content; }
use the below code in template wherever u needed
<?php echo excerpt(25); ?> <?php echo content(300); ?>
Adding Menu Option In WordPress Backend
Add this to functions.php in ur theme directory
register_nav_menus( array( 'footermenu' => __( 'menu in footer', 'twentyten' ), ) );
use the below code in template wherever u needed
<?php wp_nav_menu(array('menu_class'=>'footer_menu', 'theme_location' => 'footermenu') ); ?>
Getting All Images From WordPress Post
Function
<?php function postimage($size=thumbnail, $qty=-1) { if ($images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => $qty, 'post_mime_type' => 'image'))) { foreach( $images as $image ) { $attachmenturl=wp_get_attachment_url($image->ID); $attachmentimage=wp_get_attachment_image( $image->ID, $size ); echo $attachmentimage; } } else { echo "No Image"; } } ?>
Using Function
<?php postimage(array(32,32)); ?>
where 32,32=>image height width