In your HTML, did you manually write those URLs like that?
<ul>
<li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=schoes">Shoes</a></li>
<li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=clothes">Clothes</a></li>
<li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=beauty">Beauty</a></li>
</ul>
If so, can you just replace them with the following:
<ul>
<li><a href="https://www.site.com/immagini/schoes">Shoes</a></li>
<li><a href="https://www.site.com//immagini/clothes">Clothes</a></li>
<li><a href="https://www.site.com/immagini/beauty">Beauty</a></li>
</ul>
That way, you will get the exact URL you’re looking for.
Now, in order to translate one of the URLs, I’d add the gallerytag
query var to WordPress:
add_rewrite_tag('%gallerytag%', '([^&]+)');
Then I would add the rewrite rule:
add_rewrite_rule(
'^immagini/([-a-z]+)/?$',
'index.php?pagename=immagini&gallerytag=$matches[1]',
'top'
);
After that, create a custom page template for the immagini
page by putting a file in your themes folder called page-immagini.php
(or use the ID if the name may change) with the following contents:
<?php
global $wp_query;
echo '<pre>' . print_r($wp_query, true) . '</pre>';
Now, after you flush the permalinks and you visit example.org/immagini/
you’ll see $wp_query
printed out.
If you visit example.org/immagini/test
, you’ll see that there will be a new element in the array like this:
[gallerytag] => test
With this, you can then query for the pictures with that tag.
If you want to automatically display a list of all the tags in your immagini
page, you can use something like this:
global $post;
$gallerytags = get_terms('ngg_tag');
echo '<ul>';
foreach ($gallerytags as $tag) {
echo '<li><a href="' . get_permalink($post->ID) . $tag->slug . '">' . $tag->name . '</a></li>';
}
echo '</ul>';
Let me know if this answers your questions.