Posted on Leave a comment

WordPress: How to display custom taxonomy terms in select field in options panel of redux framework?

bwNAorV

Its very easy to show custom taxonomies as select options list in the options panel of redux framework.

I used following paremeter to get list of custom taxonomies:

 'fields'     => array(
                 array(
                'id'          => 'slider_type',
                'type'        => 'select',
                'title'       => __( 'Select Slider for Homepage', 'redux-framework-demo' ),
                'subtitle'    => __( '' ),
                'desc'        => __( 'Above you will select the slider from the list of slider types which you created.', 'redux-framework-demo.', 'redux-framework-demo' ),
                'data'        => 'terms',
                'args'        =>  array('taxonomies'=>'slidertype', 'args'=>array('hide_empty'=>0)),
            ),
       )

 

Posted on Leave a comment

WordPress: how to add custom classes in wp_nav_menu using custom walker calass?

Sometimes we need to add custom classes in the the navigation menus created by wordpress’ function ‘wp_nav_menu’. For example we want to add custom classes for dropdown menus, in such spcific cases we there is no option to add custom class for dorpdown menu. So in that case we can use walker abstract class.
We will create a new class in functions.php extending wordpress class “Walker_Nav_Menu” of  “Walker” Class. We can set any name to our new walker class. i.e. Primary_Walker_Nav_Menu

Example:

Class: Primary_Walker_Nav_Menu in functions.php

// walker class to add custm classes in the header menu
class Primary_Walker_Nav_Menu extends Walker_Nav_Menu {

function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
    $output = str_replace("menu-item-has-children", "menu-item-has-children dropdown", $output);
  }
}

Navigation Menu Function: wp_nav_menu

 $defaults = array(
              'theme_location'  => 'primary',
              'menu'            => '',  // name of the menu you created in the menus
              'container'       => '',
              'container_class' => '',
              'container_id'    => '',
              'menu_class'      => '',
              'menu_id'         => '',
              'echo'            => true,
              'fallback_cb'     => 'wp_page_menu',
              'before'          => '',
              'after'           => '',
              'link_before'     => '',
              'link_after'      => '',
              'items_wrap'      => '<ul id="%1$s" class="%2$s nav navbar-nav navbar-right menu">%3$s<li class="search"></li></ul>',
              'depth'           => 0,
              'walker'          => new primary_Walker_Nav_Menu() // this is the walker class we created to alter default menu html
            );
           
             wp_nav_menu( $defaults );

 

Posted on Leave a comment

jQuery Baisc Standard Form Validation Script

<div id="status" class="alert alert-danger" style="display:none"></div>
<div class="alert alert-success" style="display:none"></div> 
   
<script>
  function validation()
  {
    
    var firstName = $('#firstName').val();
    var lastName = $('#lastName').val();
    var phone = $('#phone').val();
    var email = $('#email').val();
    var message = $('#message').val();
    
    $(".alert-danger").slideUp();
    
    if((firstName == '') || (lastName == '') || (phone == '') || (email == '') || (message == '') )
    {
      var empty_field_title='';
      if(firstName=='') {empty_field_title='First Name';}
      else if(lastName==''){empty_field_title='Last Name';}
      else if(phone==''){empty_field_title='Phone';}
      else if(email==''){empty_field_title='Email';}
      else if(message==''){empty_field_title='Message';}

      show_error('<strong>Error: </strong>'+empty_field_title+' is required.'); 
      return false; 
    }
    else if(!(/^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-])+(\.+[a-zA-Z]{2,4}){1,2})$/i.test(email)))
    {
      show_error('<strong>Error: </strong> Email address format is not correct.');
      return false;
    }
    
    
    return true;
      
  }

function show_status(msg, type)
{
	 if(type=="error")
	 {
	  	var status_class=".alert-danger";
	 }
	 else
	 {
	  	var status_class=".alert-success";
	 }

	   $('.alert-danger, .alert-success').slideUp();

	   setTimeout(function(){
	   		$(status_class).html(msg);
	   }, 400);

	   $(status_class).slideDown();
	 
	   // scrolling to the error
	   $('html, body').animate({
	    	scrollTop: $("#status").offset().top
	   }, 2000);
}
  </script>

 

Posted on Leave a comment

PHP: How to Transfer File from Server to Server Online using PHP?

// you can increase following limits according to size of remote file.
ini_set('max_execution_time', '30000');
ini_set('memory_limit', '30000');

/* Source File URL */
$remote_file_url = 'http://www.Your_remote_url.com/Your_File.zip';
 
/* New file name and path for this file */
$local_file = 'Your_File.zip';
 
/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );
 
/* Add notice for success/failure */
if( !$copy ) {
    echo "Copy Failed\n";
}
else{
    echo " File is successfully copied.\n";
}