How do I eliminate stink from a waste water pipe?
Cut the current pipe and install the p-trap near the bottom, close to however it's vented.  Retain the cut piece of pipe and add it back above the new p-trap.

Gluing to the top (as mentioned in comments) will cause an overflow issue.