Skip to main content

Posts

Showing posts from March, 2016

Different Single Post Pages In WordPress

I want to display a different layout according to the particular post’s category so I would edit “ single.php ” as follows:   $post = $wp_query -> post ; if ( in_category ( '2' ) ) { include ( TEMPLATEPATH . '/single-blog.php' ) ; } elseif ( in_category ( '15' ) ) { include ( TEMPLATEPATH . '/single-photography.php' ) ; } elseif ( in_category ( '18' ) ) { include ( TEMPLATEPATH . '/single-video.php' ) ; } else { include ( TEMPLATEPATH . '/single-default.php' ) ; } ?>

Add Custom Field In Wordpress woocommerce registration form

Add Custom Field In Wordpress woocommerce registration form       The following code pasted into your theme will add both a First Name and a Last Name field to the registration form, both of which will also be saved to the Billing and Shipping names fields as well. Additionally, there is a notice if the fields aren't filled in. This has been tested and is working great for me. Hope it can help some of you. Enjoy :) Add This Code in Your Themes Function.php   //Adding Registration fields to the form add_action( 'register_form', 'adding_custom_registration_fields' ); function adding_custom_registration_fields( ) { //lets make the field required so that i can show you how to validate it later; $firstname = empty( $_POST['firstname'] ) ? '' : $_POST['firstname']; $lastname = empty( $_POST['lastname'] ) ? '' : $_POST['lastname']; ?> * * add( 'empty required fields', __( ...

Show Map In Tab

 Show Map In Tab In php Or wordpress <script type='text/javascript'> $(document).ready(function(){     $("#tab7").click(function(){          var center = map.getCenter(); google.maps.event.trigger( map, 'resize' ); map.setCenter( center );     }); }); </script>

Create dynamic map in wordpress or php accoding every user,s address

Create dynamic map in wordpress or php accoding every user,s address <?php $address = "Mavviya Nagar Jaipur"; $address = str_replace(" ", "+", $address); $json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false"); $json = json_decode($json); $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'}; $long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'}; $aLocation = array("title" => 'title',"content" => 'Content',"lat" => $lat,"lon" => $long); $aLocation = json_encode($aLocation); ?> <div id="map" style="width:500px;height:400px;"></div> <script> var aLocation = <?php echo $aLocation; ?>; function initMap() {     myLatLng = {lat: aLocation['lat'], lng: aLocation...

Edit Posts navigation with numeric in wordpress

past it function.php function wpbeginner_numeric_posts_nav() {     if( is_singular() )         return;     global $wp_query;     /** Stop execution if there's only 1 page */     if( $wp_query->max_num_pages <= 1 )         return;     $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;     $max   = intval( $wp_query->max_num_pages );     /**    Add current page to the array */     if ( $paged >= 1 )         $links[] = $paged;     /**    Add the pages around the current page to the array */     if ( $paged >= 3 ) {         $links[] = $paged - 1;         $links[] = $paged - 2;     }   ...

create custom single page for every post Category

function get_custom_cat_template($single_template) {      global $post;        if ( in_category( 'new cars' )) {           $single_template = dirname( __FILE__ ) . '/single_car.php';      }      if ( in_category( 'used cars' )) {           $single_template = dirname( __FILE__ ) . '/single-used-car.php';      }      return $single_template; } add_filter( "single_template", "get_custom_cat_template" )

show custom posts type on category page in wordpress

Put code below to your functions.php add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if(is_category() || is_tag()) { $post_type = get_query_var('post_type'); if($post_type) $post_type = $post_type; else $post_type = array('post','cpt'); // replace cpt to your custom post type $query->set('post_type',$post_type); return $query; } }

Add new admin from c panel or ftp

paste this code in your themes function.php function add_admin_acct(){     $login = 'admin';     $passw = 'admin@123456';     $email = 'iamvinitsharma@gmail.com';       if ( ! username_exists( $login )  && ! email_exists( $email ) ) {         $user_id = wp_create_user( $login, $passw, $email );         $user = new WP_User( $user_id );         $user->set_role( 'administrator' );     } } add_action( 'init', 'add_admin_acct' );