Displaying titles in a thumbnail gallery

I am displaying a thumbnail gallery (slider with thumbnails underneath). There isn’t an option to display the title of the main image either above or below it. You can only display the title on top of the image which is not what I want. Due to this, I decided to connect the gallery to a dataset. I added a text field above the main image of the gallery and connected the text field to the dataset’s title field. The issue is that the text field keeps displaying the title of the first item on the dataset even when I click on a different image. I tried using the code below, but it’s not working. What am I doing wrong?

$w.onReady( function () {
$w( “#text1” ).text = $w( “#dataset1” ).getCurrentItem().title;
});