Tuesday, December 31, 2013

Embed view block or page in code or block

We can embed a views page or block in code or block.

<?php print view_embed_view('view_name', 'block_page_name'); ?>

Apply row style template in Drupal 7

We can design or apply our own design to drupal views (row style) in Drupal 7.

*) Goto Views -> Block or Page view -> Advanced -> Other -> Theme: Information.
*) Create the template file in your custom theme folder. Possible template file name can be created from "Row style output" in Theme: Information.
*) If required, please apply "Rescan template files" button.
*) Once rescan done, your template will be shown as bold.
*) Then press "Row style output" link, copy the code and paste into your template file.
*) Then you can design or apply your own design.

For Example: 
Create views-view-fields--<view name>--<view machine name>.tpl.php in theme folder
And apply the following code

<div class="ownclass">
    <a href="<?php echo $fields['field_link']->content; ?>">
        <?php echo $fields['field_image']->content; ?>
    </a>
</div>

Programmatically Apply image style in Drupal 7

We can set the image style programmatically in Drupal 7.

1. Configuration -> Media -> Image Styles -> Add Style
2. image_style_url('style_name', 'path');

Ref: https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7
Example:
print image_style_url('thumbnail', $node->field_image['und'][0]['uri']);

Thursday, December 26, 2013

Get rows count in Drupal 7

<?php

$query = db_select('table1')->fields('users')->execute();
$count = $query->rowCount();

?>

Thursday, April 4, 2013

Magento site redirected to localhost from live server

After developed magento website in localhost, files will be moved to live server environment. The following needs to be changed in your live server. Other wise your live server URL will redirected to localhost path.


Step 1: Edit old URL values in database 
Table: core_config_data
Columns: web/unsecure/base_url, web/secure/base_url
In this table you need to edit the field named value to your live environment url!

Old Values:
web/unsecure/base_url - http://localhost/magentotest
web/secure/base_url  - https://localhost/magentotest

New Values:

web/unsecure/base_url - http://magentolive.com
web/secure/base_url  - https://magentolive.com




Step 2: Clear the cache folder 
Magento retains all configuration cache in /var/cache folder
You should clear the entire contents in this cache folder. Magento will regenerates all these files when needed.

Saturday, January 19, 2013

Remove index.php from requested url in magento

Steps to remove index.php from requested url in magento.

1. Goto root/var folder and open .htaccess file and remove existing lins and repalce the following lins,


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

2. Goto System->Configuration->Web->Search Engines Optimization, change to "Yes".
3. Goto System->Cache Management->Clear all cahces