Tuesday, September 16, 2014

Show a default image if one doesn’t exist!!!

Do you want to show default image if the image url doesn’t exist? Using jQuery it can be done. Please try the following code..

var img = $('img');
var default_url = "http://example.org/images/img.jpg";
var img_url = "http://example.org/images/" + some_variable + ".jpg";
img.error(function() {
  $(this).attr('src', default_url) 
});
img.attr('src', img_url);

Sunday, September 14, 2014

Installing PHP Mongo Driver on MAMP

To install latest Mongo driver on MAMP

1 - install autoconf using homebrew or Mac Ports
brew install autoconf
2 - Download php 5.4.10 source from php.net.
3 - rename uncompressed php source folder from php-5.4.10 to php and paste it in this folder
/Applications/MAMP/bin/php/php5.4.10/include/
4- using the terminal open php folder and run ./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
5 - Add MAMP bin to your ~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile
6 - install latest mongo
pecl install mongo
7- restart MAMP server :).
8- Enable the extension Edit /Applications/MAMP/bin/php/php5.4.10/conf/php.ini Add the following line after the section named "; Extensions":
extension=mongo.so

Friday, September 12, 2014

Few tips on Wordpress and few Cheet Sheet


Improve Page Titles


If you want the page title to be the title of the post, edit header.php  file  and change the title tag as follows:

<title>
<?php if ( is_home() ) {  bloginfo('name'); echo(' — ');  bloginfo('description'); } else wp_title('',true); ?>
</title>


Improve Permalink Structure


If you want to have the page urls for each post as http://www.mysite.com/seo-title/

Follow

> Login
> Go to Options
> Then click on Permalinks
> Change the format to ‘Custom’ with the following format
/%postname%/
> Submit

You can also use post slugs to manually tweak the url. E.g. You might want to change:
http://www.mysite.com/long-and-very-long-title-might-not-good-looking/
http://www.mysite.com/short-one/


Date Problem solution for Post


When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.
Use <?php the_time( get_option( 'date_format' ) ); ?> to add the date set in the admin interface.

Wordpress : The Loop Visual Model