Query in Magento

Magento have own standard of query,

    $products   = $product->setStoreId($storeId)->getCollection()
	->addAttributeToFilter('featured', array('Yes'=>true))
	->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner');

If we want to add the other condition like
for random case,

$products->getSelect()->order(new Zend_Db_Expr('RAND()'));

for to limit


Vi commands: Simple and Quick tutorial

VI is a display oriented interactive text editor originally created for the Unix operating system. It is available by default on all UNIX systems. It is supplied with all Linux distributions.

Here is a simple and quick VI command tutorial.

Note: VI commands are CASE SENSITIVE.


There are two modes in vi: command mode and insert mode.
All vi commands work on command mode.

– Hitting Esc will put you in command mode
– Hitting i and a in command mode will put you in insert mode.
– Hitting i will insert text before the cursor
– Hitting a will append text after the cursor

Creating new file

– Open terminal (In Ubuntu, press: CTRL + ALT + T)
– Type the following command to create new file named hello.txt:
vi hello.txt

vi -r filename = recover filename that was being edited when system crashed

Saving file

– After you enter some text to your file, press Esc
– Then type “:w” (without quote)

Exit vi

– press Esc
– type “:q” (without quote)

:wq = save any changes and quit vi
ZZ = save any changes and quit vi
:q! = quit vi even though latest changes have not been saved

Moving Cursor

– h j k l will move cursor left, down, up, right respectively
– 0 (zero) will move cursor to start of current line
– $ will move cursor to end of current line
– w e b will move forward one word, forward to next end of a word, and back one word, respectively
– :0 (zero) or 1G will move cursor to first line in file
– :n or nG will move cursor to line n
– :$ or G will move cursor to last line in file

Moving through screen

CTRL f will move forward one screen
CTRL b will move backward one screen

Deleting Text

x = delete single character
dd = delete entire current line
dw = delete single word beginning with character under cursor
db = delete word backward
D = delete the remainder of the line, starting with current cursor position
d$ = delete from cursor to end of line (same as D)
d0 = delete from cursor to beginning of line
dL = delete from current line to end of screen
dG = delete from current line of end of file
d) = delete complete sentence forward
d( = delete complete sentence backwards

Undo and Redo

u = undo last command
. (dot) = redo/repeat last command

Copy and Paste

yy = copy current line
yw = copy word forward
yb = copy word backward
Y = copy the remainder of the line, starting with current cursor position
y$ = copy from cursor to end of line (same as Y)
y0 = copy from cursor to beginning of line
yL = copy from current line to end of screen
yG = copy from current line to end of file
y) = copy from cursor to start of sentence
y( = copy from cursor to end of sentence
p (lowercase) = paste to the line below the current line
P (uppercase) = paste to the line above the current line
Lines and words deleted from dd and dw can also be pasted.


/string = search forward for occurence of string
?string = search backward for occurence of string
n (lowercase) = find the next occurence of the search
N (uppercase) = find the previous occurence of the search

Find and replace

:%s/foo/bar/g = replace all occurences of foo with bar in the entire file

s = substitute
g = global, i.e. the action should be performed for all instances of a string found on any given line
% sign = “Do this for all lines in this buffer.”

Other find and replace commands:-

:s/foo/bar/ = replace the first occurrence of the word foo on the current line with the word bar.
:s/foo/bar/g = replace all occurrences of the word foo on the current line with the word bar.
:%s/foo/bar/g = replace all occurrences of the word foo in the current file with the word bar.
:%s/foo//g = delete all occurrences of the word foo in the current file.

Reading and writing to file

– Open terminal
– Type vi and hit enter
– :r filename = read file named filename
– :w newfile = write the recently read content to newfile

Set commands

:set nu = display line numbers
:set nonu = cancel line number display
:set ts=4 will set the number of spaces used to display the tab character to 4
:set ic = make string searches with / ignore cases
Example: After :set ic using /foobar will find foobar as well as FooBaR

Shell operations

We can execute any shell command inside vi itself.

:!command = execute command without leaving vi
Example: :!date = display date

We can start a new command shell inside vi itself.

:sh = start a new command shell inside vi
Type exit to leave that shell and return back to vi.



Copied from : http://blog.chapagain.com.np/vi-commands-simple-and-quick-tutorial-linux/

Custom image size and autocrop options

WordPress provides different sizes of images , the size of the uploaded image can be edited form Setting > Media and give the required value .But sometime we may need other sizes imaged too so for that purpose we can use the function.php of the theme for custom options. I found it from


Just add

add_image_size($name, $width, $height, $cropBoolean);

For example : add_image_size('featuredImageCropped', 250, 200, true);


Limit excerpt length by characters (Multiple excerpt)

I wanted to have multiple excerpt for my site in wordpress . I googled and find numerious one but

http://wordpress.org/support/topic/limit-excerpt-length-by-characters helped me alot.
We can simple add

 function get_excerpt($count){
 $permalink = get_permalink($post->ID);
 $excerpt = get_the_content();
 $excerpt = strip_tags($excerpt);
 $excerpt = substr($excerpt, 0, $count);
 $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
 $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
 return $excerpt;

and it by

echo get_excerpt(125);

Ways to prevent wordpress blog.

During the research on the how to make wordpress site secure , i encounter with this url ,http://www.mastermindblogger.com/2011/14-ways-to-prevent-your-wordpress-blog-from-being-hacked/.
Here it explain simple but the very valuable methods for the wordpress blog being hackced.

Using themes in WordPress…………

What is a Theme?

Fundamentally, the WordPress Theme system is a way to “skin” your weblog. Yet, it is more than just a “skin.” Skinning your site implies that only the design is changed. WordPress Themes can provide much more control over the look and presentation of the material on your website.

A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. A Theme modifies the way the site is displayed, without modifying the underlying software. Themes may include customized template files, image files (*.jpg, *.gif), style sheets (*.css), custom Pages, as well as any necessary code files (*.php). For an introduction to template files, see Stepping Into Templates.

Let’s say you write a lot about cheese and gadgets. Through the use of the WordPress Loop and template files, you can customize your Cheese category posts to look different from your Gadgets category posts. With this powerful control over what different pages and categories look like on your site, you are limited only by your imagination. For information on how to use different Themes for different categories or posts, see The Loop in Action and Category Templates.
Get New Themes

The WordPress Theme Directory is the official site for WordPress Themes which have been checked and inspected, and are free for downloading. The site features the ability to search by type and style, and offers a demonstration of the page view elements of the Theme.
Using Themes

WordPress supplies two Themes in its distribution for your initial use. You can switch between these two Themes using the admin panel. Themes that you add to that directory will appear in the Administration Panels > Design > Themes as additional selections.
Adding New Themes
Appearance Panel

There are many Themes available for download that will work with your WordPress installation.

If the Theme that you are installing provides instructions, be sure to read through and follow those instructions for the successful installation of the Theme. It is recommended that Theme developers provide installation instructions for their own Themes, because Themes can provide special optional functionality that may require more steps than the basic installation steps covered here. If your Theme does not work after following any provided instructions, please contact the Theme author for help.

To add a new Theme to your WordPress installation, follow these basic steps:

1. Download the Theme archive and extract the files it contains. You may need to preserve the directory structure in the archive when extracting these files. Follow the guidelines provided by your Theme author.
2. Using an FTP client to access your host web server, create a directory to contain your Theme in the wp-content/themes directory provided by WordPress. For example, a Theme named Test should be in wp-content/themes/test. Your Theme may provide this directory as part of the archive.
3. Upload the Theme files to the new directory on your host server.
4. Follow the instructions below for selecting the new Theme.

Adding New Themes using cPanel

If your host offers the cPanel control panel, and the Theme files are in a .zip or .gz archive follow these instructions. Note: This assumes the Theme you download is a compressed (zip) file and the files in the zip file are in their ‘named’ folder.

1. Download the Theme zip file to your local machine.
2. In cPanel File Manager, navigate to your Themes folder. If you have WordPress installed in it’s own folder called wordpress, you would navigate to “public_html/wordpress/wp-content/themes” and if WordPress is installed in your web-root folder you would navigate to “public_html/wp-content/themes”.
3. Once you’ve navigated to the Themes folder in cPanel File Manager, click on Upload file(s) and upload that zip file you saved in Step 1.
4. Once the zip file is uploaded, click on the zip file name in cPanel, then in the panel to the right, click on Extract File Contents, and that zip file will be uncompressed.
5. Follow the instructions below for selecting the new Theme.

Adding New Themes using the Administration Panel

You can download Themes directly to your blog by using the Add New Themes option in the Appearance sub-menu.

1. Log in to the WordPress Administration Panel.
2. Select the Appearance panel, then Themes.
3. Select Install Themes
4. Use the sub-menu or the Search or Filter options to locate a Theme you would like to use.
5. Click on the Preview link to preview the Theme or the Install link to upload the Theme to your blog.
6. Use the Upload link in the top sub-menu to upload a zipped copy of a Theme that you have previously downloaded to your machine.

Selecting the Active Theme

To select a Theme for your site:

1. Log in to the WordPress Administration Panel.
2. Select the Appearance panel, then Themes.
3. From the Available Themes section, click on the Theme title (or Theme screenshot) for the Theme you wish to activate.
4. A preview of the Theme will be shown.
5. To activate the Theme click the Activate “Theme Name” link in the top right.

Your selection should immediately become active.

Note: If the Theme preview is blank, do not activate the new Theme without investigating further. Your site may not be displayed correctly, otherwise.

Adsense Tips and Tricks

“Do You Know the Way to Earn Hundreds of $ in Just One Hour or Even Less” “Here we will show you the fastest, Easiest way to get your slice of the Cash-Filled Google AdSense Program” Even While You’re Sleeping! The latest online money-making strategy is Google’s AdSense and AdWord programs. Each can improve your income, but first you need to know how they work.

One of the latest online money making strategies is to use Google’s AdSense and or to use Google’s AdWord programs. Each of these programs has the potential to improve your cash flow, however, you need to know how these programs work before you can make a realistic estimate about the kind of money you will be able to earn, and before you can determine which program(s) is/are best for you. AdSense is a marketing affiliate program where you place specially selected Google-generated advertisements on your web page that reflects the information and content of your web page. In return for hosting these ads you are paid based on the number of ad images, click throughs, or purchases made because of your web page. Google’s AdSense program automatically matches the best possible advertisements with the content on your Web page, making the ads magically quite relevant to your content.

What makes this more interesting is that advertisers don’t pay to have their adverts show up on either Google or separate content sites, but instead pay when the ads are clicked by customers, what we call “pay per click” or PPC. A percentage of the amount that the company pays Google for displaying the ad is then shared with the AdSense-enabled web site owner.

Website owners pay Google to display these ads and are charged a predetermined amount every time their ad gets clicked by a web surfer. With the AdSense program, you will display these same text ads on your site just like Google and get paid for it as well.

All you do is copy and paste some provided HTML code into your pages and Voila! The ads will show up. Every time an ad is clicked on your site, you will receive a certain percentage of what Google receives from the advertiser. Once your account reaches $100, you’ll receive a check in the mail.

Google does not disclose exactly how much you’ll earn per ad that is clicked. The commission you receive per click depends on how much advertisers are paying Google for the particular ad. You will earn a share of that amount. I’ve heard of earnings anywhere from 2 cents to $15 per click. The amount you’ll earn also depends largely on the amount of targeted traffic you receive to your own site, how well the ads match your audience’s interests, the placement of the ads on your pages, and of course the amount you receive per click.

To become an affiliated member of AdSense you first will be required to fill out an application. Once your application is approved you will receive a block of HTML code that you will need to program into your website so that AdSense will be able to run and be able to be tracked on your website.

There isn’t a fee to participate in AdSense, however, you do need to invest time in setting up AdSense features and filters. You will also have to pay for the design, hosting, and domain name of your website. In order for you to make money, you will need to attract visitors to your website. To do this you will need to provide your viewers with quality content that appeals to a large audience. One popular way to do this is to provide a blog of current events, issues, opinion, commentary, etc. Another way is to produce original content that people will drool over. Be creative. There is a lot of competition out there, so learn how to produce content that will top the search engine results, and learn how to use keywords to your advantage in order to attract more viewers.

Important Warning: Do not click on your ads!

I think one of the most common mistakes that new AdSense participants make is to click on an advert or three to “make a quick buck”. Sounds good in theory, but you’ll end up kicked out of the AdSense program if you click on ads shown on your own pages, which is not a good strategy for earning money! Once your AdWords account has been set up and activated, and your billing information has been entered, your ads will then be up and running within a matter of minutes. To maximize your benefits with AdWords, you will need to design advertisements that meet all of the requirements that they set out, as well as create a concise ad that tells your potential customers exactly what you offer. Anyway, it’s simple, easy to accomplish, you never have to negotiate (or even talk) with advertisers, you don’t have to bill anyone at all, and every month or two you’ll get a nice little check from Google corporate.

Starting Right Now, its fast, it’s easy and most importantly, and it is a proven-successful strategy for making fast money online. Don’t waste hours of time or tons of money using information that may or may not work! So what’re you waiting for? Let’s get started!

Famous 5-Minute Install of WORDPRESS.

The Following article is form the wordpress site:
http://codex.wordpress.org/Installing_WordPress. Hope you can install wordpress on fly.

Famous 5-Minute Install

Here's the quick version of the instructions, for those that are already comfortable with performing such installations. More detailed instructions follow.

If you are not comfortable with renaming files, Steps 3 and 4 are optional and you can skip them as the install program will create wp-config.php file.

Download and unzip the WordPress package if you haven't already.
Create a database for WordPress on your web server, as well as a MySQL user who has all privileges for accessing and modifying it.
Rename the wp-config-sample.php file to wp-config.php.
Open wp-config.php in a text editor and fill in your database details as explained in Editing wp-config.php to generate and use your secret key password.
Upload the WordPress files in the desired location on your web server:
If you want to integrate WordPress into the root of your domain (e.g. http://example.com/), move or upload all contents of the unzipped WordPress directory (but excluding the directory itself) into the root directory of your web server.
If you want to have your WordPress installation in its own subdirectory on your web site (e.g. http://example.com/blog/), create the blog directory on your server and upload WordPress to the directory via FTP.
Run the WordPress installation script by accessing wp-admin/install.php in a web browser.
If you installed WordPress in the root directory, you should visit: http://example.com/wp-admin/install.php
If you installed WordPress in its own subdirectory called blog, for example, you should visit: http://example.com/blog/wp-admin/install.php

That's it! WordPress should now be installed.