Include navigation (arrows) and pagination (dots) on each slide itself in a slick slider

If you want to include navigation (arrows) and pagination (dots) on each slide itself in a slick slider, here's how you can achieve this:

1. HTML Structure

You need to place arrows and dots inside each slide so that they appear uniquely for each one.

Slide 1

Slide 2

Slide 3

2. Initialize Slick

Use Slick’s API to manage navigation and pagination for each slide:

$(document).ready(function () {
  $('.slider').slick({
    slidesToShow: 1,
    slidesToScroll: 1,
    infinite: true,
    speed: 500,
    arrows: false, // Disable global arrows
    dots: false, // Disable global dots
  });

  // Add custom controls for each slide
  $('.slider .slide').each(function (index, slide) {
    const $prevButton = $(slide).find('.prev');
    const $nextButton = $(slide).find('.next');

    // Go to the previous slide on click
    $prevButton.on('click', function () {
      $('.slider').slick('slickPrev');
    });

    // Go to the next slide on click
    $nextButton.on('click', function () {
      $('.slider').slick('slickNext');
    });

    // Generate custom dots for this slide
    const $dotsContainer = $(slide).find('.dots');
    const slideCount = $('.slider .slide').length;

    for (let i = 0; i < slideCount; i++) {
      const dot = $(``);
      dot.on('click', function () {
        $('.slider').slick('slickGoTo', $(this).data('slide'));
      });
      $dotsContainer.append(dot);
    }
  });

  // Sync active dots with slick events
  $('.slider').on('afterChange', function (event, slick, currentSlide) {
    $('.custom-dot').removeClass('active');
    $(`.custom-dot[data-slide="${currentSlide}"]`).addClass('active');
  });
});

3. CSS Styling

Make it visually appealing with CSS:

.slider {
  position: relative;
}

.slide {
  text-align: center;
  position: relative;
}

.controls {
  position: absolute;
  bottom: 20px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.controls .prev,
.controls .next {
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.controls .prev:hover,
.controls .next:hover {
  background-color: #0056b3;
}

.controls .dots {
  display: flex;
  gap: 5px;
}

.controls .custom-dot {
  background-color: #ddd;
  border: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  cursor: pointer;
}

.controls .custom-dot.active {
  background-color: #007bff;
}

4. Final Outcome

  • Each slide now has its own arrows and pagination dots.
  • Clicking on these controls interacts seamlessly with the slick slider.
  • Dots update dynamically to reflect the current active slide.

Using jQuery, we can easily hide and restore the placeholder when the user clicks on the field

you can use jQuery to hide the placeholder when a user focuses on a field and restore it when they blur (leave) the field. Here's an example:

Input field HTML: 

jQuery Code:

$(document).ready(function () {
	const $input = $('#nameField');

	$input.on('focus', function () {
		$(this).data('placeholder', $(this).attr('placeholder')); // Save placeholder
		$(this).attr('placeholder', ''); // Remove placeholder
	});

	$input.on('blur', function () {
		$(this).attr('placeholder', $(this).data('placeholder')); // Restore placeholder
	});
});

Explanation

Focus Event:

  • Triggered when the input field is clicked or gains focus.
  • Save the current placeholder value in a custom data attribute (data('placeholder')) and clear the placeholder.

Blur Event:

  • Triggered when the input field loses focus.
  • Restore the placeholder from the saved data attribute.

Magento 1.9 - Display New Products in Magento with Pagination

Display New Products in Magento with Pagination

Follow the following steps:

1. Create all of the folders/file in the following path if they do not already exist.
   app/code/local/Mage/Catalog/Block/Product/New.php

2. Put the below code on New.php
    <?php

    class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_List
    {
       function get_prod_count()
       {
          //unset any saved limits
          Mage::getSingleton('catalog/session')->unsLimitPage();
          return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
       }// get_prod_count

       function get_cur_page()
       {
          return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
       }// get_cur_page

       /**
        * Retrieve loaded category collection
        *
        * @return Mage_Eav_Model_Entity_Collection_Abstract
       **/
       protected function _getProductCollection()
       {
          $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

          $collection = $this->_addProductAttributesAndPrices($collection)
             ->addStoreFilter()
             ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
             ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
             ), 'left')
             ->addAttributeToSort('news_from_date', 'desc')
             ->setPageSize($this->get_prod_count())
             ->setCurPage($this->get_cur_page());

          $this->setProductCollection($collection);

          return $collection;
       }// _getProductCollection
    }// Mage_Catalog_Block_Product_New
    ?>

3. Put bellow lines on  app/design/frontend/default/your_theme/layout/catalog.xml

<reference name="content">
   <block type="catalog/product_new" name="product_new" template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>10</category_id></action>
      <action method="setColumnCount"><column_count>6</column_count></action>
      <action method="setProductsCount"><count>0</count></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
         <block type="page/html_pager" name="product_list_toolbar_pager" />
         <action method="setDefaultGridPerPage"><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
         <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
      </block>
      <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>
   
4.  Put bellow line on CMS page
{{block type="catalog/product_new" column_count="6" products_count="0" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/list.phtml"}}

Njoy :)

Retrieve coupon details from coupon code WooCommerce

In order for the WC_Coupon function to work, I needed to add the "new" keyword prior to calling the function. As demonstrated below.
$coupon_code = 'save10percent';
global $woocommerce;
$c = new WC_Coupon($coupon_code);
Now I can get details about the coupon like so
 echo "Discount Amount ".$c->amount;//Get Discount amount
echo "Discount Type ".$c->discount_type;//Get type of discount
echo "Individual Use ".$c->individual_use;//Get individual use status
echo "Usage Count ".$c->usage_count;//Get number of times the coupon has been used
echo "Uage Limit ".$c->usage_limit;//Get usage limit
echo "Coupon Description ".$c->description;//Get coupon description

Search only post type in wordpress

By default wordpress search provides a searching function on whole site whether it is pages or post type. In order to make the search only post type in wordpress, below is the code you need to copy and paste it in to your function.php file.

 function filter_search($query) {
if ($query->is_search) {
  $query->set('post_type', array('post','page'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');
?>
Notice the line that says
 $query->set('post_type',array('post','page'));
We can filter the search results by changing the values in the array variable. Right now it is set to display posts and pages but you can modify it to display anything we required.

Create a coupon programatically in WooCommerce

We will need to add this code to our child theme’s functions.php file or via a plugin that allows custom functions to be added. We always have to remember, we don’t have to add custom code directly to our parent theme’s functions.php file as this will be wiped entirely when we update the theme.

/**
 * Create a coupon programatically
 */
$coupon_code = 'UNIQUECODE'; // Code
$amount = '10'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
     
$coupon = array(
 'post_title' => $coupon_code,
 'post_content' => '',
 'post_status' => 'publish',
 'post_author' => 1,
 'post_type'  => 'shop_coupon'
);
     
$new_coupon_id = wp_insert_post( $coupon );
     
// Add meta
update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
update_post_meta( $new_coupon_id, 'individual_use', 'no' );
update_post_meta( $new_coupon_id, 'product_ids', '' );
update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
update_post_meta( $new_coupon_id, 'usage_limit', '' );
update_post_meta( $new_coupon_id, 'expiry_date', '' );
update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
update_post_meta( $new_coupon_id, 'free_shipping', 'no' );

WooCommerce Account Page Custom Endpoint

We can do it using below simple steps. We have to add the below code given in steps in our theme functions.php or in plugin code.

Step 1: In this post, we will see how we can add custom endpoint to my account page in front means one new our own page like order, download (default one’s). To do this, first we’ll add rewrite endpoint using WordPress function ‘add_rewrite_endpoint’ on ‘init’ hook.

function aft_custom_endpoint() {
  add_rewrite_endpoint( 'custom', EP_ROOT | EP_PAGES );
}
 
add_action( 'init', 'aft_custom_endpoint' );

Step 2: Now, we will add menu item for this custom endpoint on WooCommerce My Account page menu so that we can access easily. For this we’ll use ‘woocommerce_account_menu_items’ filter.

add_filter( 'woocommerce_account_menu_items', 'aft_new_menu_items' );
 
/**
* Insert the new endpoint into the My Account menu.
*
* @param array $items
* @return array
*/
function aft_new_menu_items( $items ) {
    $items[ 'custom' ] = __( 'Custom', 'webkul' );
    return $items;
}

The above code will add one more menu item named Custom at the end of my account page menu list.

Step 3: The endpoint has been added, menu item also added, now next thing will be, how can we add content to this new (say) page..? Not to worry, WooCommerce provide the hook using which we can add content –

$endpoint = 'custom';
 
add_action( 'woocommerce_account_' . $endpoint .  '_endpoint', 'aft_endpoint_content' );
 
function aft_endpoint_content() {
    //content goes here
    echo '//content goes here';    
}

How To Change the Author URL Slug in wordpress


Are you looking for a way to change the author URL slug? This snippet will change the default slug, mysite.com/author/name, to mysite.com/profile/name. However, you can change this to anything that you would like.
Instructions:
  1. Add this code to your theme’s functions.php file or in site-specific plugin.
  2. Change profile in line 4 to any name you would like.
add_action('init', 'cng_author_base');
function cng_author_base() {
    global $wp_rewrite;
    $author_slug = 'profile'; // change slug name
    $wp_rewrite->author_base = $author_slug;
}
Note: If changes is not reflecting after adding the code, you can check after updating permalink setting from back-end.

How to check custom fields exists or not

Add a custom field

Now lets just add a custom fields value to our post. After checking the custom fields checkbox, scroll down to the page to see the Custom Fields box. Write your first custom fields name under the Name. It will be a kind of variable to call in our template file. After that write a value you want to display in your post. It should be done under the Value tab.

Get custom fields value to our post

To get the custom fields value we do not need to add any function into the function.php file. Its quite easy to get it by the simple wordperss function.
Just copy the below code into your theme or where you want to display the value.

echo get_post_meta($post->ID, 'Your Custom Fields Name', true);

Check if the custom fields exists or not

With the help of of some if else conditional statement we can check weather the our custom fields name has a value or not.

$key = 'sub-heading';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') { 
 echo '

'.get_post_meta($post->ID, 'sub-heading', true).'

'; }

Adding CC and BCC contact form 7

CC and BCC are emails general header object in which CC means to be Carbon Copy and BCC means Blind Carbon Copy. CC consists of a email id. Adding CC and Bcc contact form 7 is very easy.

CC: example@xyz.com

When an email is composed to send to your client and you want the same email to be sent to you secondary email ID at the same time CC is used. BCC is like CC but it hide the email id of secondary.

One of very popular plugin called contact form 7 has an admin interface that allows you to manage your contact form via admin. It is necessary to know how to add CC and BCC to your contact form 7 via admin panel. You can follow these below steps to accomplished this easy task.

  • Login to your Dashboard
  • Find contact tab on the left panel
  • Click on specific contact form from the form listing.
  • Now click on Mail tab and go to Additional Headers section.
  • Now add your cc email id by following the format ( CC: your-email-id@hosting.com)
  • Scroll down to click on save

HTML5 default validation for confirm password

In this section, we am going to see how you we easily validating HTML5 default validation for confirm the password. Generally in HTML5 when we create a form we simply write “required” attribute to the form element and it starts validating itself without other javascript code. But for confirm password validation we would required to add few lines of code that will set the validation in the default way.

HTML

Confirm password with HTML5

JAVASCRIPT

var password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");

function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}

password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;

Wordpress Update User's Password with PHP

It worked for me to update 'user_pass' using both update_user_meta and wp_update_user:


update_user_meta($user_id, 'user_pass', $newpassword);
wp_update_user( array ('ID' => $user_id, 'user_pass' => $newpassword) ) ;

Get first letter of each word for a given string in PHP

QUESTION:How would I get the first letter of each word for a given string?

$string = "This Is The TEST String";
$result = "TITTS";

ANSWER: explode() on the spaces, then you use the [] notation to access the resultant strings as arrays:

$words = explode(" ", "This Is The TEST String");
$acronym = "";

foreach ($words as $w) {
  $acronym .= $w[0];
}

If you have an expectation that multiple spaces may separate words, switch instead to preg_split()

$words = preg_split("/\s+/", "This Is The TEST String");

Or if characters other than whitespace delimit words (-,_) for example, use preg_split() as well:

// Delimit by multiple spaces, hyphen, underscore, comma
$words = preg_split("/[\s,_-]+/", "This Is The TEST String");

How to Allow Only One Checkbox to be Checked using jQuery

Generally, we use radio buttons to let a user select ONE option from a limited number of choices. Most of the cases radio buttons are ideal to select a single option from a group of the options. But sometimes you required to use the checkbox to do the same functionality like a radio button. If you want to allow the user to check only one checkbox from a group of the checkboxes, it can be done easily using jQuery.
How to Allow Only One Checkbox to be Checked using jQuery
At first, include the jQuery library.

Use the following code to allow only one checkbox to be checked using jQuery.

HTML

 Male
 Female
 Other

JavaScript

$(document).ready(function(){
    $('input:checkbox').click(function() {
        $('input:checkbox').not(this).prop('checked', false);
    });
});

Remove Contact Form 7 CSS and JS Unless Contact form 7 shortcode is used in the page

Remove Contact Form 7 CSS and JS Unless Contact form 7 shortcode is used in the page
Question :
Want to show the css and javascript only when the shortcode is used in that page. If the short code not present in the wordpress page then the js and css of contact form should not be shown.
Solution code for : Remove Contact Form 7 CSS and JS Unless Contact form 7 shortcode is used in the page
Here is the answer for your question. If there is not shortcode the css and js of contact form will be removed and if there is shortcode css and js will be added.
function aft_lwp_contactform_css_js() {
    global $post;
    if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7') ) {
        wp_enqueue_script('contact-form-7');
         wp_enqueue_style('contact-form-7');

    }else{
        wp_dequeue_script( 'contact-form-7' );
        wp_dequeue_style( 'contact-form-7' );
    }
}
add_action( 'wp_enqueue_scripts', 'aft_lwp_contactform_css_js');