useful functions for wordpress

//*******woocomerce>>>>>>>>//





/*****cart item and amount*****/


 <div class="cart-icon col-sm-4">
 <?php global $woocommerce; ?>

 <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>">

 <?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?>  <?php echo $woocommerce->cart->get_cart_total(); ?></a>
<a href="<?php echo get_permalink( 67 ) ;?>">  <i class="fa fa-shopping-cart"></i></a>



 </div>


//category post per page (function.php, shows 24 products)//

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );

///////////////////////////////////////












//*******atribute calling*******/

 <span><?php $arr =  $product->get_attributes('pa_500ml'); // field name pa_500ml
  //var_dump( $product->get_attributes('pa_500ml'));
  //echo $arr["300ml"]["name"];
   echo $arr["500ml"]["value"];
   ?><!--500ml  |  25 AED--></span>


/******************************/

//related product numbers (add to function.php)//

// Redefine woocommerce_output_related_products()
function woocommerce_output_related_products() {
woocommerce_related_products(4,2); // Display 4 products in rows of 2
}

///////////////////////////////////












//to gt content of category//
 <?php

   $args = array(
     'posts_per_page' => '4',
    'post_type'      => 'product',
'product_cat' => 'signature-blends',
//'order' => 'ASC',
    'meta_query'     => array(
        'relation' => 'OR',
        array( // Simple products type
           // 'key'           => '_sale_price',
            'value'         => 0,
            'compare'       => '>',
            'type'          => 'numeric'
        ),
        array( // Variable products type
            //'key'           => '_min_variation_sale_price',
            'value'         => 0,
            'compare'       => '>',
            'type'          => 'numeric'
        )
    )
);
?>
<?php
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
           
//////////////////////////////////////////////////////////

















/*****(for login)*******/



 <?php if ( is_user_logged_in() ) { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
<?php }
else { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?></a>
<?php } ?>


////////////////////////////////////////////////////////////



//get permalink of cat and id//


 <li><a href="<?php echo get_permalink(188, 'product_id');?>">Geranium</a></li>     (for id)

<a href="<?php echo get_term_link(18, 'product_cat' )?>">View More <i class="fa fa-angle-right"></i></a> (for cat)
/////////////////////////////////////



//////////////////////////////////********************///////////////////////////////




/**********/

  <?php
if (is_category()) {
$yourcat = get_category ($cat);
echo ''.$yourcat->slug;
}
?>


/***********************/

















/***show categroy name in singel.php page********/

<?php if(is_single()) {
$category = get_the_category();
$title = $category[0]->cat_name;
echo $title; } ?> ">

//////////////


/******select category & give condition*******/

  <?php

   
if( is_category(array ( "Fall 2008" , "womenswear-1" , "womenswear-2" , "womenswear-3" , "womenswear-4" , "womenswear-5" , "menswear"))){
   
  ?>
       <a href="<?php echo get_permalink( 1033 );?>"><p>2010-2014 <br/>

        <?php
if (is_category()) {
$yourcat = get_category ($cat);
echo ''.$yourcat->slug;
}
?>  <br/>

      Earlier references</p></a>
     
     
     
     
     
       <?php } else{?>
     
     
     
     
     
       <a href="<?php echo get_permalink( 9 );?>"><p>2010-2014 <br/>

         <?php
if (is_category()) {
$yourcat = get_category ($cat);
echo ''.$yourcat->slug;
}
?>  <br/>

      Earlier references</p></a>
     
     
     
     
     
     


<?php }?>



/****************/




















/******date function*********/

<?php echo get_the_date('j F, Y');?>

<?php relative_post_the_date(); ?> (with relative tym 45 minutes ago)


/*********************/


/***** for words limit*********/

<?php echo wp_trim_words( get_the_content(), 50 );?>

/***********/


/***** else in thumbnail*********/

 <?php  if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/logo-south.png" />';
}
?>

/***********/













/****google map iframe***/


 <iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $address; ?>&output=embed"></iframe>



/************************/


///////call for image zoom(magic zoom plugin)/////////

  <?php $post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
?>            

                    <a class="MagicZoom"  href="<?=$post_thumbnail_url?>"> <?php the_post_thumbnail('full');?> </a>


////////////////////////////////////////////////




/*****blog on dashboard ******/
<?php
add_action( 'init', 'blog' );
function blog() {
    register_post_type( 'blog',
        array(
            'labels' => array(
                'name' => 'blog',
                'singular_name' => 'blog',
                'add_new' => 'Add New Blog',
                'add_new_item' => 'blog',
                'edit' => 'Edit',
                'edit_item' => 'Edit',
                'new_item' => 'New',
                'view' => 'View',
                'view_item' => 'View',
                'search_items' => 'Search ',
                'not_found' => 'No Adress found',
                'not_found_in_trash' => 'No address found in Trash',
                'parent' => 'Parent news'
            ),

            'public' => true,
            'menu_position' => 4,
            'supports' => array( 'title','editor','thumbnail','comments','custom-fields' ),
            'taxonomies' => array( '' ),
            'menu_icon' =>  get_template_directory_uri().'/images/blog.jpg',
            'has_archive' => true
        )
    );
}
?>

/********************/



/******slider in dashboard***********/

function my_custom_sliders_posttype(){



$args = array(

'labels'=> array( 'name'=>'sliders',

'singular_name'=> 'slider',

'menu_name'=>'sliders',

'name_admin_bar'=> 'sliders',

'all_items' =>'View all sliders',

'add_new'=> 'Add New sliders' ),

'description' =>"This post type is for sliders",

'public' => true,

'exclude_from_search'=>false,

'publicly_queryable'=> true,

'show_ui' => true,

'show_in_menu'=> true,

'show_in_admin_bar'=> true,

'menu_position'=>6,

'capability_type'=> 'page',

'supports'=> array( 'title', 'editor', 'author', 'thumbnail', 'excerpt',

),

'query_var'=>true,





);



register_post_type( "sliders", $args );

}



add_action("init","my_custom_sliders_posttype");



/********************/












/****show data in popup*****/

<div class="container">
<div class="top-btn text-center">
       <a type="submit" class="btn btn-default  signup-btn"  data-toggle="modal" data-target="#quote_box" >SIGN UP NOW</a>
</div>
       
       
        <!-- Modal -->
<div class="modal fade" id="quote_box" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel"> </h4>
      </div>
      <div class="modal-body">







<div id="mc_embed_signup">
<form action="//autisminsideout.us9.list-manage.com/subscribe/post?u=3551e64937cfa8f02dc58f30b&amp;id=78a2d29258" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
 <h2>I want to know more about Autism Inside Out</h2>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
 <label for="mce-EMAIL">Email Address  <span class="asterisk">*</span>
</label>
 <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
 <label for="mce-FNAME">First Name </label>
 <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group">
 <label for="mce-LNAME">Last Name </label>
 <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
</div>
 <div id="mce-responses" class="clear">
  <div class="response" id="mce-error-response" style="display:none"></div>
  <div class="response" id="mce-success-response" style="display:none"></div>
 </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;"><input type="text" name="b_3551e64937cfa8f02dc58f30b_78a2d29258" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function(cash) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
<!--End mc_embed_signup-->



      </div>
    </div>
  </div>
</div>


/**************************/











/****showing comment count***/

<?php  echo get_comments_number()." Comment" ;?>

/###????///////



/********widget create code **********/

register_sidebar( array(
  'name'          => __( 'footer Links', 'twentythirteen' ),
  'id'            => 'sidebar-4',
  'description'   => __( 'appair in footer' ),
  'before_widget' => '',
  'after_widget'  => '',
  'before_title'  => '',
  'after_title'   => '',
 ) );


/*****widge calling code*****/

<?php
     if ( is_active_sidebar( 'sidebar-4'  ) ) :
dynamic_sidebar( 'sidebar-4' );
endif
     ?>

/***********************/



   
     /******menu code******/\
 
      <?php

$defaults = array(
'theme_location'  => '',
'menu'            => '',
'container'       => 'div',
'container_class' => '',
'container_id'    => 'bs-example-navbar-collapse-1',
'menu_class'      => 'nav navbar-nav',
'menu_id'         => '',
'echo'            => true,
'fallback_cb'     => 'wp_page_menu',
'before'          => '',
'after'           => '',
'link_before'     => '',
'link_after'      => '',
'items_wrap'      => '<ul id="%1$s" class=" nav navbar-nav ">%3$s</ul>',
'depth'           => 0,
'walker'          => ''
);

wp_nav_menu( $defaults );

?>

/***************/







/******search code*****/

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/"  >
   <input type="text" id="search" class="form-control"   value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" placeholder="Search" />
   <input class="btn btn-default" type="submit" id="searchsubmit" value="Submit"  />
   </form>
 
   /************/
 









 
   /***** remove version from ctrl+u ********/
 
   remove_action( 'wp_head', 'wp_generator' ) ;
  remove_action( 'wp_head', 'wlwmanifest_link' ) ;
  remove_action( 'wp_head', 'rsd_link' ) ;
 
 
   /****************/
 
   /****page calling code*******/
 
   <?php
    $query = new WP_Query( 'post_type=page&p=49' );
    while ( $query->have_posts() ) : $query->the_post();?>
   
   
    <?php endwhile;?>
    /******/
   











   
    /*******call post from id******/
   
    <?php
$post = get_post($id); //assuming $id has been initialized
setup_postdata($post);?>

/***************************/
   
   











   
    /*******post calling code***/
   
   
    <?php
$the_query = new WP_Query( array('cat'=> 2 , 'posts_per_page' => 2)); ?>
<?php if ( $the_query->have_posts() ) : ?>
 <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>


    <div class="section2img col-sm-6 mar30b transition">

    <div class="contr2 floatright">
        <h3 class="red-box"><?php the_title() ;?></h3>
        </div>
            <?php
  if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
     the_post_thumbnail();
       } ?></div>
    <div class="section2txt col-sm-6  mar30b  transition">
   
    <div class="contr2">
    <h2><?php the_title() ;?></h2>
        <p><?php the_content() ;?></p>
       
    </div>
   
    </div>
  <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
<?php endif; ?>
   
   
   
    /******/
   
   
   
   
   








   
   
    /**pagination code **/
   
   <?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;
 }

 if ( ( $paged + 2 ) <= $max ) {
  $links[] = $paged + 2;
  $links[] = $paged + 1;
 }

 echo '<div class="navigation"><ul>' . "\n";

 /** Previous Post Link */
 if ( get_previous_posts_link() )
  printf( '<li>%s</li>' . "\n", get_previous_posts_link() );

 /** Link to first page, plus ellipses if necessary */
 if ( ! in_array( 1, $links ) ) {
  $class = 1 == $paged ? ' class="active"' : '';

  printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

  if ( ! in_array( 2, $links ) )
   echo '<li>…</li>';
 }

 /** Link to current page, plus 2 pages in either direction if necessary */
 sort( $links );
 foreach ( (array) $links as $link ) {
  $class = $paged == $link ? ' class="active"' : '';
  printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
 }

 /** Link to last page, plus ellipses if necessary */
 if ( ! in_array( $max, $links ) ) {
  if ( ! in_array( $max - 1, $links ) )
   echo '<li>…</li>' . "\n";

  $class = $paged == $max ? ' class="active"' : '';
  printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
 }

 /** Next Post Link */
 if ( get_next_posts_link() )
  printf( '<li>%s</li>' . "\n", get_next_posts_link() );

 echo '</ul></div>' . "\n";

}
?>
  /****************************/
 











 
 
  /*************calling pagination code *****************/

    <div class="col-sm-12 pagination">
  <?php //twentythirteen_paging_nav(); ?>
 <div class="navigation">
         <?php wpbeginner_numeric_posts_nav(); ?>
        </div>
        </div>


/*********************/














/****code to call custom field**/


<?php
                $key_1_value = get_post_meta( get_the_ID(), 'para', true );

                // check if the custom field has a value

                if( ! empty( $key_1_value ) ) {

                 echo do_shortcode($key_1_value);

                }
?>
/**********/
               













/*********************slider code******************************/    

 <!-- Wrapper for slides -->
              <div class="carousel-inner">
               <?php
$class_active="active";

$args=array(
  'cat'=> 22,
  'post_status' => 'publish',
  'posts_per_page' => 3,
 
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
             
                <div class="item <?php echo $class_active ;?>">
               
                  <div class="carousel-caption">
                  <p> <?php echo the_content();?> </p>
              </div>
                  </div>
                   <?php
$class_active="";
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>
                 
 
                </div>


//////////////////////////////////////////////////////////////          
             
              custumn field image calling
               
                <?php $imageid = get_post_meta($post->ID, 'image', true);?>
<?php $size = "medium";?>

<?php if($imageid){?>
<img src="<?php echo wp_get_attachment_url( $imageid, $size ); ?>" />

<?php } else{?>




<div class="field-data">

<p><?php echo get_field("data");?></p>
</div>

<?php }?>

Comments

Popular posts from this blog

remove span elements from Contact form 7 but keeping inside elements

Elance HTML5 Test Answers