Star Trek (1966-1969).
Or maybe as T.J. Hooker (1982-86), the veteran cop paired with rookie Vince Romano (Adrian Zmed). But in a 50-plus year career, he's played hundreds of characters, including some beefcake and buddy-bonding roles.
Billy Budd, the young cabin boy who draws the erotic interest of the captain in a 1955 tv adaption of the Herman Melville novel.
Peter Gifford in The Explosive Generation (1960), who causes a scandal by teaching sex ed in high school (his students include Lane Kinsolving, Billy Gray of Father Knows Best, and a very young Beau Bridges).
In Vanished (1971), a powerful presidential adviser (Arnold Green) vanishes. The White House tries to cover up the fact that he was gay. Shatner plays a reporter trying to uncover the truth.
Not a lot of gay roles, but he did appear on the drag queen-friendly Madame's Place in 1982, and he played a homophobic lawyer on a 2007 episode of Boston Legal, assigned the case of a judge who is suing a company for not "curing" his "same-sex attraction disorder."
And in his 2010-2011 sitcom $h*! my Dad Says, his Ed has a gay assistant.