Offset for Loop

It’s a php error probably because its expecting either one of your if statements to be closed before the endwhile. It’s hard to tell without seeing all the code but at a guess check this one is closed:

if ($tags) {

also I would wrap your foreach in curly brackets. Maybe just preference though…

foreach($tags as $individual_tag){ $tag_ids[] = $individual_tag->term_id; }

Just go through the code and make sure everything is closed properly. It’s not an error on line 165, it’s before there but that’s just where php realises somethings wrong and throws the error.