I think I may have piles. But it only hurts when I go to toilet to poo?

That is not uncommon. Since you have bleeding - you should get it medically checked. It's important not to make hemorrhoids worse. Cleaning off after a bowel movement should be gentle. Pre-moistened towlettes can be used to dab the anus. Don’t wipe/rub. Pat the anus dry after cleaning. Avoid using harsh soaps that contain dyes or aromas. Cotton underwear is helpful as it absorbs moisture well. Sitz bathes can be.
Sounds like. You have anal fissure. But impossible to tell without examination. Consult a physician.