Top Questions

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Mar 17, 2016
    <script type="text/javascript">
    
    var cssfeed=new gfeedfetcher("example1", "example1class", "")
    cssfeed.addFeed("CSS Drive", "your rss link") //Specify "label" plus URL to RSS feed
    cssfeed.displayoptions("date") //show the specified additional fields
    cssfeed.setentrycontainer("li") //Display each entry as a list (li element)
    cssfeed.filterfeed(10, "title") //Show 10 entries, sort by date
    cssfeed.init() //Always call this last
    
    </script>

     

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Jan 22, 2016

    add confirmation alert before your link active

    <script>
    function confirmDelete(delUrl) {
      if (confirm("Are you sure you want to delete")) {
        document.location = delUrl;
      }
    }
    </script>
    
    <a href="javascript:confirmDelete('delete.page?id=1')">Delete</a>
    
    or
    
    <a href="delete.page?id=1" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
    
    or
    use this cdn's in your header
    
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.css
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.js
    
    
    <a href="delete.page?id=1" class="confirmation">Delete</a>
    
    jQuery('.confirmation').click(function (e) {
        var href = jQuery(this).attr('href');
    
        swal({
            title: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes",
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        window.location.href = href;
                    }
                });
    
        return false;
    });
    

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Nov 19, 2016

    split time interval in 15 min slot using php

    $array_of_time = array ();
    $start_time    = strtotime ("2013-08-28 17:45:00");
    $end_time      = strtotime ("2013-08-28 22:15:00");
    
    $fifteen_mins  = 15 * 60;
    
    while ($start_time <= $end_time)
    {
       $array_of_time[] = date ("Y-m-d H:i:s", $start_time);
       $start_time  = $fifteen_mins;
    }
    
    print_r ($array_of_time);
     
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Sep 9, 2018

    Customer session does not work except some pages

    Method 1.  To check if customer is logged: (best way)Create helper file like Data.phphow to create custom helper or module https://www.dorcode.com/blog/52/how-to-create-and-use-helpers-in-magento-2


    <?php
    namespace Magento\Mytheme\Helper;
    
    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_customerSession;
        protected $_customerSessionn;
    
        public function __construct(\Magento\Framework\App\Helper\Context $context,
                \Magento\Framework\App\Request\Http $request,
                \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
                \Magento\Customer\Model\SessionFactory $customerSession,
                \Magento\Customer\Model\Session $customerSessionn
            ) 
        {
            $this->request = $request;
            $this->customerRepository = $customerRepository;
            $this->_customerSession = $customerSession;
            $this->_customerSessionn = $customerSessionn;
            parent::__construct($context);
        }
        public function getCustomerName(){
            $customer = $this->_customerSession->create();
            return $customer->getCustomer()->getName();
        }
        public function isLoggedIn()
        {
            return $this->_customerSessionn->isLoggedIn();
        }
    }
    ?>
    
    Call to your template :
    
    <?php
    $myhelper = $this->helper('Magento\Mytheme\Helper\Data');
    $cname=$myhelper->getCustomerName();
    $isLoggedIn=$myhelper->isLoggedIn();
    
    if ($isLoggedIn):
    	   echo 'login';
    else : 
    	  echo 'not login';
    endif;
    ?>
  • 5.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : Mar 15, 2018

    You can specify a function identifier in a custom property in your .ajax() call and use the value of that in your ajaxComplete() callback.

    For example, get any ajax property while making your .ajax() call:
    function foo() {
        $.ajax({
            url: 'my-page.php',
        });
    }
    
    And then, use any of ajax property to ajaxComplete() like this:
    $('#my-unique-id').ajaxComplete(function(e, xhr, settings) { // run after all ajax complete 
        if (settings.url == 'my-page.php') { // write condition according to your requirement
            // execute you code
        } else {
            // execute you code
        }
    });
     
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Jan 11, 2018

    A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

    Note: The setcookie() function must appear BEFORE the <html> tag.
    public function add_cookies($name,$value="",$time=3600) {
    	$this->load->helper('cookie');
    	if($value=="") {
    		return json_decode(get_cookie($name),true);
    	}
    	$val=$value;
    	if($val!="") {
    		$search1=get_cookie($name);
    		if($search1!="") {
    			$search1=json_decode($search1,true);
    			if(!in_array($val, $search1)) {
    				$search1[]=$val;
    				$cookie= array(
    				       'name'   => $name,
    				       'value'  => json_encode($search1),
    				       'expire' => $time,
    				   );
    				set_cookie($cookie);
    			}
    		} else {
    			$value=array();
    			$value[]=$val;
    			$cookie= array(
    			       'name'   => $name,
    			       'value'  => json_encode($value),
    			       'expire' => $time,
    			   );
    			set_cookie($cookie);
    		}
    	}
    	return json_decode(get_cookie($name),true);
    }
     
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Dec 29, 2016

    you can prevent your page if some changes has been done on page.and show warning to user if they won't to leave page

    function enableBeforeUnload() {
        window.onbeforeunload = function (e) {
            return "Discard changes?";
        };
    }
    function disableBeforeUnload() {
        window.onbeforeunload = null;
    }
    $('input, textarea, select').change(function(event){
      enableBeforeUnload();
    });
    /***Using Jquery**/
    $('#formid').submit(function(){
     disableBeforeUnload();
    });
    /***useing html**/
    <form action="" onsubmit="disableBeforeUnload();" method="post>
    //your code
    </form>
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Dec 7, 2015
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Aug 10, 2017

    This article, aimed at plugin developers, describes how to add Ajax to a plugin or page. Before reading this article, you should be familiar with the following

    // function.php in Wordpress -------- Start Code--------
    add_action('wp_head', 'dorcode_ajaxurl');
    function dorcode_ajaxurl() {
       echo '<script type="text/javascript">
               var ajaxurl = "'.admin_url('admin-ajax.php').'";
            </script>';
    }
    
    
    add_action( 'wp_ajax_your_dorcode', 'my_dorcode' );
    add_action( 'wp_ajax_nopriv_your_dorcode', 'my_dorcode' );
    
    function my_dorcode() {
    	$data_id = intval( $_POST['data_id'] );
        echo $data_id;
        wp_die();
    }
    // function.php in Wordpress -------- End Code--------
    
    
    
    // Anywhere in Wordpress -------- Start Code--------
    
    // if you need
    var ajaxurl = "<?php echo admin_url('admin-ajax.php') ?>";
    jQuery(document).ready(function($) {
    	var data = {
    		'action': 'your_dorcode',
    		'data_id': 1525
    	};
    	jQuery.post(ajaxurl, data, function(response) {
    		alert('Got this from the server:' + response);
    	});
    
    });
    // Anywhere in Wordpress -------- End Code--------
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jun 2, 2016

    Get last week start and end date in php

    $previous_week = strtotime("-1 week  1 day");
    
    $start_week = strtotime("last sunday midnight",$previous_week);
    $end_week = strtotime("next saturday",$start_week);
    
    $start_week = date("Y-m-d",$start_week);
    $end_week = date("Y-m-d",$end_week);
    
    echo $start_week.' '.$end_week ;