Categories
jQuery PHP Wordpress

WordPress : How to Add Infinite Scroll to Home & Category Pages

I was working on Infinite Scroll functionality in WordPress. Initially i was trying to use jetpack (WordPress plugin) to implement the same but i was not able to understand how jetpack works and i did not get proper screenshot and online support to make me understand it properly. So i have Goggled more and finally i successfully implemented Infinite Scroll on VaseemAnsari.com. You can check the home page, category page, archive page and other pages where pagination generally comes.

Let me guide you how easy it is and how can you implement the same Infinite Scroll on your WordPress blog.
Step 1. This simple functionality uses javascript “jquery.infinitescroll.min.js”. You can download a copy of “jquery.infinitescroll.min.js” from the GitHub repository, and drop it into the “scripts” or “js” folder of your WordPress theme.

Step 2. Use any Ajax loader image. I hope you already have so many or you can find loading images on Google. You can pick out the ajax-loader.gif of your choice, and add it to your theme “images” folder.

Step 3. You need to register and enqueue the required jquery.infinitescroll.min.js script in functions.php (You can find this file in your wordpress theme.)

function custom_theme_js(){
	wp_register_script( 'infinite_scroll',  get_template_directory_uri() . '/js/jquery.infinitescroll.min.js', array('jquery'),null,true );
	if( ! is_singular() ) {
		wp_enqueue_script('infinite_scroll');
	}
}
add_action('wp_enqueue_scripts', 'custom_theme_js');

Step 4. Then you need yo use below function to make the magic happen. You can write this function in functions.php file.

function custom_infinite_scroll_js() {
	if( ! is_singular() ) { ?>
	<script>
	var infinite_scroll = {
		loading: {
			img: "<?php echo get_template_directory_uri(); ?>/images/ajax-loader.gif",
			msgText: "<?php _e( 'Loading the next set of posts...', 'custom' ); ?>",
			finishedMsg: "<?php _e( 'All posts loaded.', 'custom' ); ?>"
		},
		<?php /*?>
			img				: 	The path to the ajax loader image, we put the image in plugin folder
			nextSelector	: 	Selector for the “previous posts” link.
			navSelector		: 	Containing selector for the previous/next navigation links.
			itemSelector	: 	Selector for posts. This might be .hentry, .post, .etc
			contentSelector	: 	Containing div for your posts
		<?php */?>
		"nextSelector":"#nav-below .nav-previous a",
		"navSelector":"#nav-below",
		"itemSelector":"article",
		"contentSelector":"#content"
	};
	jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
	</script>
	<?php
	}
}
add_action( 'wp_footer', 'custom_infinite_scroll_js',100 );

Check out below screenshot to know how Infinite Scroll works on my blog Twenty Thirteen and Twenty Twelve theme.

Simple Steps to add Infinite Scroll to a WordPress Blog
I have added Infinite Scroll functionality on my WordPress website. Check out the home page to see how it works

I have added Infinite Scroll to WordPress Twenty Thirteen and Twenty Twelve theme. If you have any issue in finding the proper div selectors of your theme then check below images. These images will help you to find selectors in Twenty Thirteen and Twenty Twelve Theme

You can see the Infinite Scroll working at below urls.
Twenty Thirteen Theme
Twenty Twelve Theme

I hope the above work out for you and if you still feel any issues then check the original link that helped me a lot.
Source

Categories
PHP Wordpress

WordPress : Redirect To Post Page When Search Query Returns Single Result

If your website have lots of links and people often use search box to search what they are looking for. When there is only one search result then user need to click on the title of that result to read more about that post. A solution here is why we need to show the search results page when there are only one search result.

You may use below simple php code in your WordPress theme’s functions.php file to redirect your search to the post automatically when WordPress only returns a single search result.


if (!function_exists('single_result_redirect_to_post')){
	add_action('template_redirect', 'single_result_redirect_to_post');
	function single_result_redirect_to_post(){
		if (is_search()) {
			global $wp_query;
			if ($wp_query->post_count == 1) {
				wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
			}
		}
	}
}
Categories
PHP Wordpress

WordPress : Send Mail to Admin when user comes to 404 page

Sending mails to admin is very easy in wordpress by using a inbuild wordpress function wp_mail.
But if you want to send a mail to wordpress admin when user comes to 404 page then you can use below simple code.

Sending mail when user comes to 404 page in wordpress
This code can be added in your wordpress theme’s functions.php file or in custom plugin. You need to write a custom plugin for the same. Please let me know if you need any help to write a custom plugin. As i am using a custom plugin for my wordpress websites and that custom plugin have lots of functions and wordpress hooks that makes my life easy and simple.

Below script checks the referring link of your website, and then sends an email to the webmaster/wordpress admin.

if (!function_exists('email_admin')){
	function email_admin(){
		$message = "";
		if(isset($_SERVER['HTTP_REFERER'])){
			$message .= "User came from: ".$_SERVER['HTTP_REFERER']."\r\n";
		}
		$ipAddress 		= 	$_SERVER["REMOTE_ADDR"];
		if($ipAddress!=''){
			$message .= "Track User Data: http://www.ip-adress.com/ip_tracer/".$ipAddress."\r\n";
		}
		$browser 		= 	$_SERVER['HTTP_USER_AGENT'];
		if($browser!=''){
			$message .= "Browser: ".$browser."\r\n";
		}
		$message.="Page URL they tried to access was: ".home_url().$_SERVER['REQUEST_URI']."\r\n";
		$admin_email 	= 	get_option('admin_email');
		$subject		=	'404 Error at '. home_url();
		//echo $subject;	echo $message; die;
		@wp_mail($admin_email,$subject,$message);
	}
	
	function mail_me_errors(){
		global $wp_query;
		if ($wp_query->is_404){
			email_admin();
		}
	}
	add_action('get_header', 'mail_me_errors');
}
Categories
Useful Websites and Tools

How to Send Emails In the Future Automatically

With several services popping up everyday, there are several ways in which you can send emails to yourself or others in the future, few of the reasons to do that would include sending yourself reminders (we have a talked about a better way to do that with Google calendar) or sending birthday or anniversary wishes to friends.

In this post we will introduce you to 11 services that allow you to send emails in the future, choose the one you like and start setting up those emails for forgotten birthdays.

LetterMeLater – This is probably one of the most advanced future email service, providing users with the ability to attach files, setup recurring emails, import contacts and more.

EternityMessage – Has a nice interface with ability to compose HTML messages with images and more, that you can save as drafts or send into the future.

l8r – l8r is a free email service that allows you to send email in the future, they also send you reminders about emails that are going to be sent in near future.

FutureMail – Allows you to send emails in the future and view them as Rss Feeds.

FutureMe – Provides a simple interface to email yourself or others in the future.

EmailFuture – Another futuristic email service provider with ability to send emails 10 years into the future.

Email Capsule – Another simple service providing you with the ability to send mails in the future.

MailFreezr – A virtual freezer for your emails, with the ability to stall your emails for 1-100 years, they do not provide date based future emails.

WhenSend – A simple, no hassle based service to send emails in the future.

YouScribbleYou – Allows you to setup recurring emails along with the ability to send emails to 2 different emails.

Bonus Service

HitMeLater – This service forwards any email you send to them in the future, for example if you send a email to 24@hitmelater.com, they will forward it back to you after 24 hours.

Which is your favorite future email service? Are you using something which is not featured in this list? Do let us know through your comments.

Categories
Career and Success

21 Best Advice for a Good life

As you know that in everyone’s life there are so many things that they want to share with other. So today i want to share the best advice that i think will be useful in your life.

1. Give people more than they expect and do it cheerfully.

2. Marry a man/woman you love to talk to. As you get older, their conversational skills will be as important as any other.

3. Don’t believe all you hear, spend all you have or sleep all you want.

4. When you say, ‘I love you,’ mean it.

5. When you say, ‘I’m sorry,’ look the person in the eye.

6. Be engaged at least six months before you get married.

7. Believe in love at first sight.

8. Never laugh at anyone’s dreams. People who don’t have dreams don’t have much.

9. Love deeply and passionately. You might get hurt but it’s the only way to live life completely.

10. In disagreements, fight fairly. No name calling.

11. Don’t judge people by their relatives.

12. Talk slowly but think quickly.

13. When someone asks you a question you don’t want to answer, smile and ask, ‘Why do you want to know?’ 🙂

14. Remember that great love and great achievements involve great risk.

15. Say ‘bless you’ when you hear someone sneeze.

16. When you lose, don’t lose the lesson.

17. Remember the three R’s: Respect for self; Respect for others; and Responsibility for all your actions.

18. Don’t let a little dispute injure a great friendship.

19. When you realize you’ve made a mistake, take immediate steps to correct it.

20. Smile when picking up the phone. The caller will hear it in your voice.

21. Spend some time alone. This will bring some peace in your life.

Categories
Career and Success

5 Better Resume Writing Tips for Freshers and Professionals

Writing a Good Resume is not a tough task. Let me help you how can you create or modify your own resume in a best way.

In preparing our Resume we should follow some important steps which should be placed in. The sections which has been put in our Resume should contain the perfect information regarding that particular categories. By looking at that Resume one should know approximately every thing about that person whom that Resume belongs to. The Resume must be clean and Original one. Don’t use photo copies. It will put bad impression at Interviewing time.
Here are the sections which has to be put in our Resume.

1. Contact section: Who are you and how can you be reached?
2. Objective statement: What do you want to do?
3. Education section: What have you learned?
4. Experience/Employment section: What can you do? What have you done?
5. Professional activities and accomplishments: How have you been recognized?
6. Miscellaneous: What else do they want to know about you?

These above mentioned categories are main things in Resume. Under these every sections you must keep proper information regarding that particular one. And sequence these sections according to what is important to the employer.

Here are some tips which should include in particular section.

1. Contact Information
In this section you should include your name , Address including street and house number and your contact number.

2. Career/Job Objective
This is recommended only for recent graduates or entry level personnel. Experience and professional job seekers rarely include it. This component of the resume can be very challenging to write. The purpose of the objective statement is to inform the reader of your career goals and qualifications. The statement should be written specifically enough to let the reader know that you have a focus to your job search. If you are considering a variety of objectives, you may want to relay the relevant objective in an accompanying cover letter.

3. Educational Qualifications
This section is most effective when you have experiences from your education that are impressive and/or directly relate to your objective. Adding this section is useful when you have developed skills and specific knowledge through your education rather than work experience. This section can be used to highlight coursework, research, or special knowledge that complements your objective. This information is useful in a resume of entry level candidates and recent graduates.

4. Employment or Experience Summary
A brief summary of qualifications can condense an extensive background by emphasizing experiences and accomplishments in brief phrases. The qualifications summary is accomplishment-oriented and provides an overview of your work experience. A summary is most appropriated for someone with substantial experience, for someone who is changing careers and wants to demonstrate transferable skills, or for someone with an eclectic background.

5. Professional Activities and Accomplishments
This part of your resume offers you the opportunity to provide insight into your career development. You should be selective and complete, listing such items as memberships in professional associations and offices held, professional registrations, honors received, and major articles or publications you have written. Do not list every article or every speech you may have given or every conference you have attended. Emphasize quality – this section of the resume should help you to demonstrate you are current and active in your profession.

6. Miscellaneous
This section covers the remaining things like hobbies, interests , strengths and goals etc. These are the main tips which we must concentrate on.

Categories
Hosting

iPage Hosting at Only $1/mo for $12 for 12 months*

This full-featured plan includes:
Unlimited Disk Space, Bandwidth & Email
Free Domain Name
Your Choice of Site Builders
ShopSite Starter Shopping Cart
Ad Credits for Google, Yahoo! & Facebook

Website Features

  • Unlimited Disk Space
  • Unlimited Bandwidth
  • FREE Domain Registration
  • Unlimited MySQL Databases
  • Drag and Drop Site Builder
  • WebSite Creator by CM4all
  • Content Management Systems (Joomla!, Drupal, Mambo, e107)
  • Blogs (WordPress, PixelPost, b2evolution)
  • Photo Galleries (Gallery2, Coppermine, ZenPhoto)
  • Forums (Gbook, phpBB, SMF)
  • Google Custom Search Engine
  • Supported Software & Scripts
  • PERL Support
  • FileManager
  • FTP with Unlimited FTP Subusers
  • Secure FTP
  • Custom Error Pages
  • URL Redirect Service
  • FrontPage Extensions
  • MIME Types
  • Visitor Statistics
  • ShopSite Starter Shopping Cart
  • osCommerce Shopping Cart
  • AgoraCart Shopping Cart
  • PayPal Integration
  • Shared SSL

Email Features

  • Unlimited mailboxes
  • Email Addresses at Your Domain
  • WebMail
  • Email Forwarding
  • Autoresponders
  • Customizable Spam Filters
  • Virus Checking

Marketing Features

  • Google Webmaster Tools
  • $100 Bonus for Google AdWords
  • $50 Credit for Facebook Ads
  • $25 Credit for Yahoo! Sponsored Search
  • FREE Yellow Pages Online Business Listing

For more info check out this link – http://www.ipage.com/secret/index.bml?cid=1668 and enter the code “HALLOWEEN” and enjoy.
I am also using the same hosting service plan from iPage and i did not feel any issues in hosting.

Categories
Magento PHP

Magento : How to Update Product Price In Cart Programmatically

If you want to Add Product to Magento Cart with Price Change then you have to write an Observer that listens the “checkout_cart_product_add_after” or “checkout_cart_update_items_after” event.
You need to modify the code as shown below.

The code is same except checkout_cart_product_add_after is called for only one item and checkout_cart_update_items_after is called for all items in the cart.

Step 1. Open etc/config.xml of your module. CodeMasterz is company name and CustomDiscount is your module name

<?xml version="1.0"?>
<config>
    <modules>
       ...
    </modules>
    <global>
        <models>
           ...
        </models>
		
		<!--Creating a observer for custom discount on cart page by Vaseem-->
		<events>
            <checkout_cart_product_add_after>
                <observers>
                    <unique_event_name>
                        <class>CodeMasterz_CustomDiscount_Model_Observer</class>
                        <method>myCustomDiscount</method>
                    </unique_event_name>
                </observers>
            </checkout_cart_product_add_after>
        </events>
		
        ...
    </global>
</config>

Step 2. Then create a file in your module folder “Model/Observer.php”

<?php
class CodeMasterz_CustomDiscount_Model_Observer
{
    
    public function myCustomDiscount(Varien_Event_Observer $observer)
    {
        $item = $observer->getQuoteItem();
        if ($item->getParentItem()) {
            $item = $item->getParentItem();
        }
        //discount 20% off
        $discount = 0.20; 
        // Check if the discount isn't applied over and over while refreshing
        //$specialPrice = $item->getPrice() - ($item->getPrice() * $discount);
		$specialPrice	=	125;
		
        if ($specialPrice > 0) {
            $item->setCustomPrice($specialPrice);
            $item->setOriginalCustomPrice($specialPrice);
            $item->getProduct()->setIsSuperMode(true);
        }
    }
?>

Hope above works for you. If you have any difficulty understanding the code or anything else then you can contact me using contact page at this website.

Categories
Magento PHP

Magento : How to Redirect Non Logged in Users to Login Page

There are some many ways to redirect users/visitors in magento. But the most easy way i found is written below.
To redirect the users/visitors to login page you can add below line of code in head.phtml of your current theme.

<?php		// Added by Vaseem to redirect non logged in user to login page
$currentUrl = $this->helper('core/url')->getCurrentUrl();
echo 'currentUrl->'.$currentUrl.'<br>';
$loginStatus	=	'';
if ( strpos( $currentUrl, "customer" ) !== false ) {
	$loginStatus	=	1;
}
if(!$this->helper('customer')->isLoggedIn() && $loginStatus!=1){
	echo 'redirect to login page now';
  	Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/login/'));
}
?>
Categories
Unknown Facts

50 Amazing Things EVERYONE should know

1 The word “queue” is the only word in the English language that is still pronounced the same way when the last four letters are removed.
2 Beetles taste like apples, wasps like pine nuts, and worms like fried bacon.
3 Of all the words in the English language, the word ‘set’ has the most definitions!
4 What is called a “French kiss” in the English speaking world is known as an “English kiss” in France.
5 “Almost” is the longest word in the English language with all the letters in alphabetical order.
6 “Rhythm” is the longest English word without a vowel.
7 In 1386, a pig in France was executed by public hanging for the murder of a child
8 A cockroach can live several weeks with its head cut off!
9 Human thigh bones are stronger than concrete.
10 You can’t kill yourself by holding your breath
11 There is a city called Rome on every continent.
12 It’s against the law to have a pet dog in Iceland!
13 Your heart beats over 100,000 times a day!
14 Horatio Nelson, one of England’s most illustrious admirals was throughout his life, never able to find a cure for his sea-sickness.
15 The skeleton of Jeremy Bentham is present at all important meetings of the University of London
16 Right handed people live, on average, nine years longer than left-handed people
17 Your ribs move about 5 million times a year, every time you breathe!
18 The elephant is the only mammal that can’t jump!
19 One quarter of the bones in your body, are in your feet!
20 Like fingerprints, everyone’s tongue print is different!
21 The first known transfusion of blood was performed as early as 1667, when Jean-Baptiste, transfused two pints of blood from a sheep to a young man
22 Fingernails grow nearly 4 times faster than toenails! Most dust particles in your house are made from dead skin!
23 The present population of 5 billion plus people of the world is predicted to become 15 billion by 2080.
24 Women blink nearly twice as much as men.
25 Adolf Hitler was a vegetarian, and had only ONE testicle.
26 Honey is the only food that does not spoil. Honey found in the tombs of Egyptian pharaohs has been tasted by archaeologists and found edible.
27 Months that begin on a Sunday will always have a “Friday the 13th.”
28 Coca-Cola would be green if coloring weren’t added to it.
29 On average a hedgehog’s heart beats 300 times a minute.
30 More people are killed each year from bees than from snakes.
31 The average lead pencil will draw a line 35 miles long or write approximately 50,000 English words.
32 More people are allergic to cow’s milk than any other food.
33 Camels have three eyelids to protect themselves from blowing sand.
34 The placement of a donkey’s eyes in its’ heads enables it to see all four feet at all times!
35 The six official languages of the United Nations are: English, French, Arabic, Chinese, Russian and Spanish.
36 Earth is the only planet not named after a god.
37 It’s against the law to burp, or sneeze in a church in Nebraska, USA.
38 You’re born with 300 bones, but by the time you become an adult, you only have 206.
39 Some worms will eat themselves if they can’t find any food!
40 Dolphins sleep with one eye open!
41 It is impossible to sneeze with your eyes open
42 The worlds oldest piece of chewing gum is 9000 years old!
43 The longest recorded flight of a chicken is 13 seconds
44 Queen Elizabeth I regarded herself as a paragon of
cleanliness. She declared that she bathed once every three months, whether she needed it or not
45 Slugs have 4 noses.
46 Owls are the only birds who can see the color blue.
47 A man named Charles Osborne had the hiccups for 69 years!
48 A giraffe can clean its ears with its 21-inch tongue!
49 The average person laughs 10 times a day!
50 An ostrich’s eye is bigger than its brain.