Thanks for your question and for including the code fragment and a link to the page on your site; very helpful. Thanks as well for digging through earlier topics and the twentytwelve-mla
example child theme. You probably found this recent topic and the earlier topics it links to:
att. tags does not show in archive
I checked your site and it looks like you’ve adapted some of the solutions suggested in the topics and code. I couldn’t match your code to the example exactly but it looks like a variation on the mla_custom_terms_list()
function in the example theme. The example function constructs links that go to a specific Page defined in your site that contains an [mla_gallery]
shortcode to display an “archive listing” with items that match the selected term. The default page slug is /tag-gallery/
, assigned earlier in the function. However, it looks like your site does not have such a page.
In the header menu bar I noticed an entry titled “X”, which links to:
https://bigbooknotes.org/attachment_tag/x/
That page is titles “Media Archives” and looks like a functioning “archive page” for the Att. Tag taxonomy; is that right? If so, the easiest solution is to modify the code on your attachment page to link to this destination.
$title = sprintf( __( 'Gallery for %1$s', 'mla-child-theme' ), $taxonomy );
foreach ( $terms as $term ) {
$output .= '<span class="terms">' . sprintf( '<a href="%1$s/%2$s/%3$s/" title="%4$s">%5$s</a>', $site_url, $taxonomy, $term->slug, $title, $term->name ) . "</span> ";
}
In the above code you can see that the href
attribute is composed from the $site_url
, $taxonomy
and $term->slug
values. The $title
attribute can be changed to suit your needs.
You can use this function with any taxonomy by changing the arguments in the second parameter. For example, to use the Att. Categories taxonomy you would code:
mla_custom_terms_list( $ID, array( 'taxonomy' => 'attachment_category' ) );
If you want to display terms from multiple taxonomies you can either call the function multiple times or modify it to accept a list of taxonomy slugs. Here is one possibility for the second alternative:
function mla_custom_terms_list( $ID, $attr = NULL ) {
// Make sure $attr is an array, even if it's empty
if ( empty( $attr ) ) {
$attr = array();
} elseif ( is_string( $attr ) ) {
$attr = shortcode_parse_atts( $attr );
}
// Create the PHP variables we need
extract( shortcode_atts( array(
'site_url' => site_url(),
'taxonomy' => 'attachment_tag',
), $attr ) );
// Extract the taxonomy/taxonomies
$taxonomies = explode( ',', $taxonomy );
// Process each taxonomy, building $output as we go
$output = '';
foreach ( $taxonomies as $taxonomy ) {
// Get the terms associated with the current attachment.
$terms = get_the_terms( $ID, $taxonomy );
if ( empty( $terms ) ) {
continue;
}
foreach ( $terms as $term ) {
$output .= '<span class="terms">' . sprintf( '<a href="%1$s/%2$s/%3$s/" title="%4$s">%5$s</a>', $site_url, $taxonomy, $term->slug, $title, $term->name ) . "</span> ";
}// foreach term
}
// Return nothing if there are no terms
if ( empty( $terms ) ) {
return '';
}
// Start with a section heading, then the links
echo "<h3>Similar Pages:</h3>\n" . $output;
}
I haven’t tested this code so you may have to fiddle with it. With this variation you can display two taxonomies with something like:
mla_custom_terms_list( $ID, array( 'taxonomy' => 'attachment_category,attachment_tag' ) );
I hope the above suggestions get you started on a solution for your application. I will leave this topic unresolved in case you have problems or further questions regarding modifying the example code for your specific needs. Thanks for your interest in the plugin.