Skip to main content

Posts

Showing posts from January, 2016

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 ...

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 ...