Since there are no toilets on smaller aircraft, how do you deal with the inevitable?
The other answers are good, but don't touch on one key method...

Prevention.

Small aircraft like a Cessna 172 have a limited cruise time, about 4 hours maximum. They are small enough that they get relatively uncomfortable after 2-3 hours, and if flying in turbulence or challenging conditions, flights can be relatively short. 

The best way I've found to avoid the problem is to make sure to use the facilities as close to departure time as possible and to limit my intake of fluids in the hour or so leading up to a flight. 

The other option you have is to land and use the "facilities". Many unmanned airports that have terminals (like KMNM) have a keypad access and facilities inside. Airports are pretty common and you usually aren't more than 30 minutes away from an airport with a bathroom.

Just as a personal account of this, I was doing night training at my local field (Class C) and it was late (10:00 PM or so). One gentleman came on the radio and asked the tower if the FBO was open so he could use the facilities. The controller responded that the FBO was closed but he could taxi him to a quiet corner of the airfield for a few minutes. The pilot gladly took him up on the offer.