18
2013
Custom queries in wordpress
We can create custom queries to show post for wordpress based websites or blogs. Custom query parameters can pass to wordpress function WP_Query. These queries cover posts, pages, taxonomies, custom fields. Following is the query for custom taxonomy with meta query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$args = array( 'post_type'=>'posttype',
'post_status' => 'publish',
'meta_query' => array(
array('key' => 'custom_key',
'compare' => '==',
'value' => 'any_value')
),
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonoy',
'field' => 'field_to_compare',
'terms' => 'field_value',
'operator' => 'NOT IN'
),
)
);
$custom_query = new WP_Query($args);
|
In above code example “posttype” is post type, in meta_query array “custom_key” is custom field name, “any_value” is custom field value, in tax_query “custom_taxonomy” is custom taxonomy name, “field_to_compare” is field name like “slug, id”, “field_value” is the value of field that is in “field_to_compare”.
For taxonomy query and meta query we must have to create array of array.
This is just one example and I used same way of custom query for one of my project. We can play with it in different ways to get our required posts.
Hope this will helpful. Thanks.
1
2013
Anonymous functions in JavaScript
The functions that are dynamically declared at runtime are called anonymous functions. They are not given name in same way as normal functions. Anonymous functions are declared by function operator. We can use the function operator to create new function.
A reference to the function that was created will be returned by function operator, and then function can be assigned to a variable, passed as parameter or returned from another function. It is possible because functions are first class objects in javascript.
Following is the example where a function is declared in normal way.
1 2 3 4 |
Function showvalue(){
Alert(“it is value”);
}
Showvalue();
|
Following is the example where the same function is declared dynamically using function operator.
1 2 3 4 5 |
Var showval;
showval = function(){
Alert(“it is value”);
};
showval();
|
26
2013
CSS property word-wrap
Word-wrap is very useful css property. It is use to break long text in new line by giving break-word with the word-wrap property. For instance, if you have text extending out the box and breaking layout then you can use word-wrap property. Word-wrap is supported in all old and new major browsers like IE 5.5+, Firefox 3.5+,Opera, Chrom and Safari.
How to use word-wrap property?
CSS property word-wrap is very easy to use. Following is example.
1 2 3 |
.wraptext{
word-wrap: break-word;
}
|
http://www.websourceblog.com_2013/03/css-property-word-wrap/
http://www.websourceblog.com_2013/03/css-property-word-wrap/
That’s it.
23
2013
Symfony commands to create new backend module.
By following symfony commands we can create module in backend. We need to run following commands in command prompt or git shell if you are using git. First create table for your module and run schema.
1 |
symfony propel-generate-crud myapp article Article |
Symfony will read the definition of Article class in the schema.yml and creates a set of templates and actions based on it in the myapp/modules/article directory.
1 |
symfony propel-init-admin backend article Article |
Above command is to Initiate an administration module. You can build an administration on a per-module basis.
Note: myapp will be your app in which you want to create module and article is table name and Article is model name.
9
2013
How to enable Remember me functionality in magento?
By default “Remember me” functionality is not enabled in magento. You can enable it form admin, very easily and quickly.
To enable it go in System->Configuration->Customers->Persistent Shopping Cart->General Options->Enable Persistence. From here select Yes from select box and click on “Save Config” button. Now refresh your site and you will see “Remember Me” along with checkbox will appear on login page. If not then clear your cache from Cache Management.
22
2013
Contact us form not sending email: magento
I was working on a magento site and setup contact form but that wasn’t sending email, just posted on contact us page and not showing any message whether email sent or not. I check form action in source code and it was empty. To make contact form working do following changes.
Opened app/design/frontend/themedirectory/template/contacts/form.phtml file and change form action as following
1 |
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post"> |
To
1 |
<form action="<?php echo $this->getUrl('contacts/index/post'); ?>" id="contactForm" method="post">
|
After making this change contact form will start working.
3
2013
How to get add to cart URL in Magento?
For add to cart button there is a function setLocation called on click in which URL, product id and quantity passed.
1 |
<input type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$product_id,'qty'=>1)) ?>')" />
|
2
2012
How to copy folder content to another folder using PUTTY?
Huge sized folders can very easily be copied to other folders by using putty copy command. It takes very less time as compare to ftp. You can take back up of sites in few seconds by using copy command.
Create folder where you want to copy content. For example, two folders copyfrom and copyto. Run following command in putty.
1 |
cp -r copyfrom/* copyto |
Above command will copy content to copyto folder. That’s it.
9
2012
SEO friendly URLs in wordpress.
WordPress have dynamic page URLs by default those are not good for search engine optimization. WordPress can generate SEO friendly URLs by using post / page or category titles. You can enable SEO friendly URLs for wordpress site from admin. To do this, see following instructions.
- Sign in wordpress admin.
- Click on Settings – > Permalinks
- There will be Default selected in Common Settings as shown in following image.
You can select any other option or you can enter custom structure if you know well about wordpress permalinks. I selected Day and name option for my blog.
When you finished click on Save Settings and refresh your blog or site to see SEO friendly URL. That’s it.
6
2012
How to register custom menus in wordpress?
You can register multiple custom menus in wordpress for your theme. These menus can be shown on different locations. There is a wordpress function that you can use for this purpose that is following.
1 |
<?php register_nav_menus( $locations ); ?> |
You can use it for multiple locations as following.
Add following code in your theme’s functions.phpfile.
1 2 3 4 5 6 7 8 9 |
<?php
if ( ! function_exists( 'register_my_menus' ) ) : ////// check function already exist…….
function register_my_menus() {
register_nav_menus(
array( 'custom-menu1' => 'Custom Menu1', 'custom-menu2' => 'Custom Menu2')
);
}
add_action( 'init', 'register_my_menus' );
?>
|
Now add these locations in your theme templates as following.
1 |
<?php wp_nav_menu(array( 'theme_location' => 'custom-menu1','container'=>'','menu_class'=>'','menu_id'=>'custom-menu1' )); ?> |
Same as for other menu. That’s it.

An article by


