There was recently a terrorist attack in Istanbul but before that happened I wanted to go there and visit other Turkish towns/cities. Is it a good idea or no? Does this usually happen?
Yes, go there. Just avoid towns close to the Syrian and Iraqi border. Make sure to not talk openly about politics, especially Kurdistan. Turkish people are very friendly and hospitable but some topics in their society are taboo.
Nothing wrong with the Kurds, it's just that you might get hit by an airstrike if you visit their villages. There's pretty much a civil war right now between the Kurds and the Turkish government broski. Don't think that conflict will bother you much as long as you're in other cities, but you should do some research about the cities that you do end up going to.
Go to Istanbul, by all means, it's incredible. And go to most of the rest of the country, other than the Syrian border or the far south-east. Check advice from eg the UK Foreign and commonwealth office.