Skip to main content

Posts

Showing posts from 2016

Add JS to the bottom of the page in Drupal 7

How to add JS at bottom of a particular page in Drupal 7 Step 1: Get the page id. In case of front page "is_front"  Step 2: In template.php file of your theme add the below code : function illume_preprocess_page(&$variables) { if ($variables['is_front']) { drupal_add_js(path_to_theme().'/js/util.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_js(path_to_theme().'/js/main.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_js(path_to_theme().'/js/slideimage.js', array('type' => 'file', 'scope' => 'footer')); $variables['bottom_scripts'] = drupal_get_js(); } } This way you can add JS file using drupal_add_js() and define scope as footer. Step 3: Now you can use bottom_script variable to the page tpl file where you want to add JS print $bottom_scripts;

How to deploy Opencart application on Hostgator or any Hosting site

Opencart hosting on shared hosting/ Hostgator Opencart is a PHP open source e-Commerce solution. Building an eCommerce application using Opencart is easy but hosting an Opencart application on any shared hosting site such as hostgator requires some little modification to your config files. On your localhost, you would have PHPMyAdmin and PHP configured on your system. You can easily build application and run it on the browser easily. In case of hosting it on shared hosting you can't just upload your application files to the public_html directory of shared hosting. It requires to configure Opencart config file for database and directories setting. I will provide you awesome trick to upload and run Opencart application without much settings and configuration. I have tried it and well tested. Just follow these below steps: Step 1: Copy your Opencart application to any other directory (Lets say /home/opencart-demo). (Just for your backup because we are going to change som

Enable SEO URL in Opencart

How to enable SEO URL in opencart 1.To use URL Alias you need to be running apache with mod_rewrite enabled.     sudo a2enmod rewrite    sudo service apache2 restart 2. In your opencart directory rename htaccess.txt to .htaccess. contain of .htaccess file Options +FollowSymlinks # Prevent Directoy listing Options -Indexes # Prevent Direct Access to files <FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">  Require all denied </FilesMatch> # SEO URL Settings RewriteEngine On RewriteBase /shop/ RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L] RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L] RewriteRule ^system/download/(.*) index.php?route=error/not_found [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

How to install Node.js on Ubuntu

Install node.js using default repository of Ubuntu Ubuntu 16.04 contains a version of node.js in its default repository. The version of this node.js is 4.2.6 sudo apt-get update sudo apt-get install nodejs To install node.js package manager npm sudo apt-get install npm To check node.js version. Type this command - node -v npm -v Install node.js using PPA Step 1: Adding PPA $ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - Step 2: Install Node.js $ sudo apt-get install nodejs Now you have done. :) Lets try an example of node.js Create a file http_server.js $ vim http_server.js add the following content var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).listen(3001, "127.0.0.1"); console.log('Server running at http://127.0.0.1:3001/'); Now to run the code on browser n

Artisan commands in Laravel

Usage of Laravel CLI tool (astisan) This is blogs is specifically for Laravel version 5.2. Artisan provides number of helpful commands for developing project. It is driven by Symfony console component. To use artisan command you should be in your project directory. 1. To see list of all artisan commands       php artisan list 2. To create controller php artisan make:controller YourController or, php artisan make:controller YourController --resource     option "--resource" will generate all REST function (index, store, show, ...) 3. To create migration table php artisan make:migration create_users_table --create=users      It will create a file in /database/migration directory. Use snake case for creating migration so that it will create class like CreateUsersTable.      To migrate tables in to the database use command: php artisan migrate       Rollback migrations: php artisan migrate:rollback 4. Create model php artisan make:model modelname

Rule to redirect on login except one-time login in Drupal 7

Redirect to front page on login and when login through one-time-login-url don't redirect to front page We can do this by Rules in Drupal Here is my rules exported code { "rules_smr_redirect_user_logins" : { "LABEL" : "SMR redirect user logins", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "ON" : { "user_login" : [] }, "IF" : [ { "NOT text_matches" : { "text" : [ "site:current-page:path" ], "match" : "user\/reset" } } ], "DO" : [ { "redirect" : { "url" : "[site:url]" } } ] } } After importing this rule you can change redirect url as per choice.

Create Wordpress custom post type

1. To create custom post type http://www.wpbeginner.com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/ 2. To create different single post template for each post type use single-{post-type name}.php 3. To create different archieve template for each post type use archieve-{post-type name}.php 4. If single page not working for custom post type         Add this to your functions.php:         /* Flush rewrite rules for custom post types. */         add_action( 'after_switch_theme', 'bt_flush_rewrite_rules' );         /* Flush your rewrite rules */         function bt_flush_rewrite_rules() {              flush_rewrite_rules();         }               Then change your theme to a different theme and then set it back again to your custom theme. This will flush the rewrite rule and making the custom post working properly.

Adding AJAX to existing node in Drupal 7

To add AJAX to existing node (content type) in Drupal 7 Every Add/Edit node has a form_id. We can use that form_id to alter the form to AJAX handler to any form element. To find form_id of node use Drupal's devel module (dpr() function) or simply just write print_r(form_id) in hook_form_alter() function. To add AJAX handler to node form field write the following code in the hook_form_alter(&$form, &$form_state, $form_id) $form['field_make'][LANGUAGE_NONE]['#ajax'] = array( 'wrapper' => 'trailer-model', 'callback' => 'smr_manage_trailer_populate_models_callback', 'method' => 'replace', 'progress' => array( 'type' => 'throbber', 'message' => "loading", ), ); Here field_make is node form field in which we are adding AJAX. Adding AJAX is same as we do in other