带有查询的锚点

I'm working on a single page website using anchors. So far i got 3 sections:

  • home (index.php)
  • photography (gallery) (index.php#photgraphy)
  • about (index.php#about)

This function reads the root folder for sub folders (categories).

    function photo_menu($gall_dir) {
     $return = NULL;
      $cat_dir = scandir($gall_dir);
       foreach($cat_dir as $cat) {
        if(is_dir("$gall_dir/$cat")) {
         if($cat !== '.' && $cat !== '..') {
          $return .= '<a href=#photography?cat=' . $cat .' class="photo_menu">' . $cat . '</a>' . PHP_EOL;
          }     
         }
        }
       return $return;
      }

De function that i'm trying to make is supposed to get the category from the url via.

And that is where i run into trouble.

Is there a way to combine the query with the anchors or is there an alternative to what i'm trying to do here?

More an HTML question than PHP.

Always put the anchor last.

$return.='<a href="index.php?cat='.$cat.'#photography" class="photo_menu">'.$cat.'</a>';