Author: NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

What is the use of Money filters in shopify ?

When in currency formatting settings of Shopify admin is set to {{ amount }} as described in this post how to change money formatting in shopify.

Then we can use these money filters to show the amounts with and without trailing zero. like here

if “HTML with currency” is ${{ amount }} CAD

{{ 14300 | money_without_trailing_zeros }}

the output of this will be $143

{{ 143 | money_without_trailing_zeros }}

the output of this will be $1.43

You can customize this in your theme files.

Pagination for custom post in wordpress

Here is how to implement Pagination for custom posts in wordpress.

Add this to functions.php


function pagination_bar() {
    global $wp_query;
 
    $total_pages = $wp_query->max_num_pages;
 
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
 
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => 'page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

Add this to page


<div class="row">
              <?php 
	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
      query_posts(array( 

        'post_type' => 'post',

        'showposts' => 4,
		'paged' => $paged

		

    ) );  

?>
              <?php while (have_posts()) : the_post(); ?>
              <div class="col-sm-6">
                <div class="tab-1"> <a href="<?php echo get_permalink(); ?>">
                  <?php the_post_thumbnail(); ?>
                  </a>
                  <h3>
                    <?php the_title();?>
                  </h3>
                  <p>
                    <?php the_excerpt();?>
                  </p>
                </div>
                <!--tab-1 --> 
                
              </div>
              <!--col-sm-6 -->
              
              <?php endwhile;?>
              
              <nav class="pagination hm">
        <?php pagination_bar(); ?>
      </nav>
            </div>

I hope this helps you .. Thanks 🙂

PHP Update Required! how to update php version in cPanel ?

Sometime we got warning in wordpress dashboard… PHP Update Required !

WordPress has detected that your site is running on an insecure version of PHP.

So here is the way to update PHP version of you website to latest one…

1) Login to your hosting cPanel and visit here.. PHP Selector

 

2) Then in new window tab change version to latest one..

 

After doing this… your website is now running on latest PHP version…

Thanks .. 🙂

 

How to create child theme in wordpress ?

How to create and customize child theme in wordpress ?

or

How to create child theme in wp ? Child theme – wordpress

Here is the way to create a child theme, based on parent or master theme in WordPress.

A child theme allows you to use and modify a master theme, and then save the child theme separately without affecting the parent theme. In case you want to update your parent theme in future then the changes will not effect on your website design.

Before you begin this guide you’ll need the following:

Access to WordPress dashboard area.
Access to file manager or FTP.

To create a new directory, you can either use FTP client or File Manager. Go to existing wp-content/themes directory and add new directory with name of parent theme and add -child to end of that directory. Like if the parent theme name is nstplanet then simply you can add new directory there with name nstplanet-child. Remember not to include any spaces in the file name because they can cause errors.

Like this directory ..

create new folder for child theme

Then add a style.css file and functions.php file inside this folder and copy and paste these things inside the files..

 style.css

/*
Theme Name: Nst Planet Child
Theme URI: http://nstplanet.com/planet
Description: Nst Planet Child Theme
Author: Narender Thakur
Author URI: http://nstplanet.com
Template: nstplanet
Version: 1.0.0
Text Domain: nstplanet-child
*/

Note : Please don’t forget to change the name as yourself theme name.



functions.php

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

After save these two files.. go to dashboard and visit Appearance > Themes. The new theme will be there as per name you given to theme

now activate child theme in wordpress

Just click on Activate to apply this theme.

To add a design overview to theme just copy screenshot.png image from the parent theme to your child theme directory.

Now you can customize the design as per your need through both files.

I hope this help you .. Thanks 🙂

 

Stop and play owl carousel on click Jquery !

How to stop and play owl carousel on click.. so here is the custom script that help you to work owl carousel as per your need.

If your owl carousel is on autoplay mode then..

// Pause on click item image
jQuery('body').on('click','.owl-carousel .item img',function(){
jQuery('.owl-carousel').trigger('stop.owl.autoplay');
var carousel = jQuery('.owl-carousel').data('owl.carousel');
carousel.settings.autoplay = false;
carousel.options.autoplay = false;
jQuery('.owl-carousel').trigger('refresh.owl.carousel');
});

After Pause the carousel if you want to play that again then..

// Replay on click close
jQuery('body').on('click','.vidpop', function(){
jQuery('.owl-carousel').trigger('play.owl.autoplay');
var carousel = jQuery('.owl-carousel').data('owl.carousel');
carousel.settings.autoplay = true;
carousel.options.autoplay = true;
jQuery('.owl-carousel').trigger('refresh.owl.carousel');
});

Note :  Please Contact with me if you are still in confusion.

I hope this help you thanks .. 🙂

wordpress how to get/show custom field value of the posts!

Here is the code .. through this you can get custom fields value from the posts in wordpress …

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

 

custom field value wp

 

Like in above image… you can apply like this

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

 

this will return value “No” from the posts…. you can apply like this for others to show the output..

 

For any help contact me here..

How to Exclude a category from WP_Query in WordPress !

Exclude Category .. Sometime we don’t want to show the posts from the particular category so here is the code you have to modify..

query_posts(array(
'post_type' => 'post',
'showposts' => 14,
'category__not_in' => 10, // category id
) );

In the above code you can find ID of that category in dashboard and can apply here..in place of 10 highlighted.

If you want to leave posts from more than 1 category then you can apply this code there..

query_posts(array(
'post_type' => 'post',
'showposts' => 14,
'category__not_in' => array(6,10), // category id's
) );


For any help contact me here..


Dynamic_sidebar() | Function | register_sidebar in WordPress !

Here is the way to add dynamic sidebar or custom widget area to your website..without using any plugin in wordpress !

<?php 
function nst_child_sidebar() {
    register_sidebar( array(
        'name' => __( 'Top bar', 'nst_child' ),
        'id' => 'top-bar',
        'description' => __( 'At header top.', 'nst_child' ),
        'before_widget' => '<div id="%1$s" class="widget-top %2$s">',
	'after_widget'  => '</div>',
	'before_title'  => '<h2 class="widgettitle-top">',
	'after_title'   => '</h2>',
     ) );	 
 
}
add_action( 'widgets_init', 'nst_child_sidebar' );
?>

In above code you can change ID and NAME etc..of the sidebar ..like above code.

You can add multiple widget’s area to site using like this…

<?php 
function nst_child_sidebar() {
   register_sidebar( array(
       'name' => __( 'Top bar', 'nst_child' ),
       'id' => 'top-bar',
       'description' => __( 'At header top.', 'nst_child' ),
       'before_widget' => '<div id="%1$s" class="widget-top %2$s">',
       'after_widget'  => '</div>',
       'before_title'  => '<h2 class="widgettitle-top">',
       'after_title'   => '</h2>',
     ) );
	 
  // Second Widget Area
 register_sidebar( array(
     'name' => __( 'Footer logos', 'nst_child' ),
     'id' => 'foot-logos',
     'description' => __( 'At Footer logos.', 'nst_child' ),
     'before_widget' => '<div id="%1$s" class="widget-footer %2$s">',
     'after_widget'  => '</div>',
     'before_title'  => '<h2 class="widgettitle-footer">',
     'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'nst_child_sidebar' );
?>

And here is the shortcode to show the widgets in php file..

<?php dynamic_sidebar( 'top-bar' ); ?>

And here is the preview area in dashboard

custom-sdiebar-wordpress

For any help contact me here..

Click to Chat