Bootstrap Templates Bundle

Wednesday, March 25, 2015

Add search option to wordpress theme



You can place a search box in your wordpress theme by using
<?php get_search_form(); ?>

You can also add

<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    <div><label class="screen-reader-text" for="s">Search for:</label>
        <input type="text" value="" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="Search" />
    </div>
</form>

After that change the id,class or style according to your need

Thursday, March 19, 2015

How to add TGM Plugin to WordPress Theme



TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference pre-packaged plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.

http://tgmpluginactivation.com/

Tuesday, February 3, 2015

Display the number of Products Sold in WooCommerce

//To display the number of units sold for a product, add the following snippet of code to your theme’s functions.php file

<?php
add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
?>

//or Where You want to show

<?php echo get_post_meta($post->ID, 'total_sales', true); ?> 



Monday, February 2, 2015

php if else sample code

This code is for those, who are facing problem with php if else


Sample 1: 


<?php if (condition): ?>
html code to run if condition is true
<?php else: ?>
html code to run if condition is false
<?php endif ?>

Sample 2: 


<?php
if(condition) { ?> 
html code to run if condition is true
<?php } ?>


Sample 3: 


<?php
     $var=1;
     if($var == 2) {
          echo “The if statement is true”;
         // or any html code to run if condition is true
     } else {
          echo “The if statement is not true”;
        // or any html code to run if condition is true
     }

?>


Sample 4:  

 The if…elseif…else Statement



<?php 
 $var=1; 
 $var2=1; 
 if($var == 2) { 
 echo “The if statement is true”; 
 } 
elseif($var == $var2) { 
 echo “The second if statement is true”; 
 } 
else { 
 echo “None of the first if statement where true”; 
 } 
?>


Sample 5:

<?php 
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>

Monday, January 12, 2015

Set WooCommerce image dimensions at the time of theme activation

Add this code to your functions.php file

/**
* Hook in on activation
*/
/**
* Define image sizes
*/
function yourtheme_woocommerce_image_dimensions() {
global $pagenow;
if ( ! isset( $_GET['activated'] ) || $pagenow != 'themes.php' ) {
return;
}
$catalog = array(
'width' => '400', // px
'height' => '400', // px
'crop' => 1 // true
);
$single = array(
'width' => '600', // px
'height' => '600', // px
'crop' => 1 // true
);
$thumbnail = array(
'width' => '120', // px
'height' => '120', // px
'crop' => 0 // false
);
// Image sizes
update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs
update_option( 'shop_single_image_size', $single ); // Single product image
update_option( 'shop_thumbnail_image_size', $thumbnail ); // Image gallery thumbs
}
add_action( 'after_switch_theme', 'yourtheme_woocommerce_image_dimensions', 1 );

Friday, January 2, 2015

Enqueue Google Fonts to WordPress Theme

Add This code to your theme functions.php file

// register styles
wp_register_style('googlefont-oswald', 'http://fonts.googleapis.com/css?family=Oswald:400,300,700', array(), false, 'all');

// enqueue styles
wp_enqueue_style('googlefont-oswald');

Thursday, January 1, 2015

How to Convert Bootstrap Menu to WordPress Menu

1. Register Menu from your functions.php file


     // This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'jhilik' ),
) );

2. Add This below code to your functions.php file 

/*--------------------------------------------
17.  Register custom navigation walker
----------------------------------------------*/
require_once('inc/wp_bootstrap_navwalker.php');


3. Put the wp_bootstrap_navwalker.php  file to your  inc folder (or any place) of your theme.
You can get the wp_bootstrap_navwalker.php  from here

4. Replace the header.php code

<ul class="nav navbar-nav">
                        <li class="active"><a href="index.html">Home</a></li>
                        <li><a href="about-us.html">About Us</a></li>
                        <li><a href="services.html">Services</a></li>
                        <li><a href="portfolio.html">Portfolio</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Pages <i class="fa fa-angle-down"></i></a>
                            <ul class="dropdown-menu">
                                <li><a href="blog-item.html">Blog Single</a></li>
                                <li><a href="pricing.html">Pricing</a></li>
                                <li><a href="404.html">404</a></li>
                                <li><a href="shortcodes.html">Shortcodes</a></li>
                            </ul>
                        </li>
                        <li><a href="blog.html">Blog</a></li> 
                        <li><a href="contact-us.html">Contact</a></li>                        
</ul>

by 


 <?php
            wp_nav_menu( array(
                'menu'              => 'primary',
                'theme_location'    => 'primary',
                'depth'             => 2,
                'container'         => 'div',
                'container_class'   => 'collapse navbar-collapse navbar-ex1-collapse',
                'menu_class'        => 'nav navbar-nav',
                'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                'walker'            => new wp_bootstrap_navwalker())
            );
        ?>







Wokiee React eCommerce Template