The beauty of the template mechanism that I’ve put into the plugin is that given enough will you should be able to accomplish anything that you can do with a normal WordPress “The Loop” driven by WP_Query. To customise the template my plugin uses you need to copy the file from wp-content/plugins/a-z-listing/templates/a-z-listing.php
into your theme at (e.g.) wp-content/plugins/your-theme-name/a-z-listing.php
.
I suspect you’ll want to use the post-id to pull your references from some location, such as a taxonomy, and append that information to the title. I’ve added the inner-most loop below (my plugin has a “letter loop” and an inner “items loop”) with a suggestion:
<?php
while ( $a_z_query->have_items() ) :
$a_z_query->the_item();
// Get the current post so you can access its ID.
$post = get_the_item_object( 'I understand the issues!' );
// Get the aliases.
$aliases = get_the_terms( $post->ID, 'aliases' );
?>
<li>
<a href="<?php $a_z_query->the_permalink(); ?>">
<?php $a_z_query->the_title(); ?>
/**
* Add the aliases here to link them to this post.
*/
</a>
/**
* Add the aliases here to have them not-linked to this post
* or to add your own links to them.
*/
</li>
<?php endwhile; ?>
The argument passed to get_the_item_object()
must read exactly I understand the issues!
to indicate to the plugin that you are aware that larger listings will be slowed or hit resource limits by using this mechanism. I will add a get_the_ID()
method on the $a_z_listing
object in a future release of the plugin to alleviate some of the related pressures.
Thank you – that’s ingenious! I’m afraid I don’t quite see how it would work, though. Presumably my custom taxonomy, subjects, would have to have a custom field called aliases which if the term is a X-ref would contain a list of comma-separated alias subjects. That’s okay, I think.
The problem is that each of those aliases would have to actually function in the same way as it does in its proper place in the list – it would have to link to all the posts that had the alias subject. Wouldn’t you have to use another loop, to find those posts? That could be very resource-hungry.
To use my previous example, an entry might look like this:
Thrush see Turdus turdus; garden birds.
If only it were possible to include two taxonomies in one listing! Then I could combine the subject taxonomy with an alias taxonomy. The alias taxonomy wouldn’t have any posts, it would simply have the entire cross-reference as its title (unlinked – the user would have to find the item referred to manually, as with a book index).
-
This reply was modified 3 years, 9 months ago by
pcgardner.
Interesting idea. You can include multiple taxonomies in the listing by modifying the shortcode:
[a-z-listing display="terms" taxonomy="main-tax,alias-tax"]
By default it will list terms from both taxonomies as links, but you could try something like this to output the titles:
<?php
$term = $a_z_listing->get_the_item_object( 'I understand the issues!' );
if ( 'main-tax' === $term->taxonomy ) :
?>
<a href="<?php $a_z_listing->the_permalink(); ?>">
<?php
endif;
$a_z_listing->the_title();
if ( 'main-tax' === $term->taxonomy ) :
?>
</a>
<?php
endif;
But the documentation says:
taxonomy: sets the taxonomy containing the terms specified in the terms=”” option
Default value: unset.
May only contain one value.
Must be the slug of the taxonomy.
Presumably the documentation is out of date. If I’d known that I could have saved myself quite a bit of time!
Anyway, thank you very much for your help. I’ll experiment with the code along the lines you suggest.
Sorry for the confusion 🙂
The documentation is split into two parts – one for display=posts
and another for display=terms
. I quoted the above suggestion assuming you were using display=terms
.
Thanks to your help I now have a fully working index with cross-references incorporated, and thought I would share my customized template in case anyone else wants to do something similar.
I set up two custom taxonomies (using PODS, but that shouldn’t make any difference). The first is ‘subject’, which has no custom fields and works like categories or tags. The second is ‘cross_reference’, with one custom field called ‘target_subjects’. For example, a cross-reference with the title ‘dunnock’ might have ‘garden birds’ in its target_subjects field.
Here is my a-z-listing.php template file; it is in the root of my theme folder. The customized section is indicated by comments.
<?php
/**
* Default multicolumn template for the A-Z Listing plugin
*
* This template will be given the variable <code>$a_z_query</code> which is an instance
* of <code>A_Z_Listing</code>.
*
* You can override this template by copying this file into your theme
* directory.
*
* @package a-z-listing
*/
/**
* This value indicates the number of posts to require before a second column
* is created. However, due to the design of web browsers, the posts will flow
* evenly between the available columns. E.g. if you have 11 items, a value of
* 10 here will create two columns with 6 items in the first column and 5 items
* in the second column.
*/
$_a_z_listing_minpercol = 10;
?>
<div id="az-tabs">
<div id="letters">
<div class="az-letters">
<?php $a_z_query->the_letters(); ?>
</div>
</div>
<?php if ( $a_z_query->have_letters() ) : ?>
<div id="az-slider">
<div id="inner-slider">
<?php
while ( $a_z_query->have_letters() ) :
$a_z_query->the_letter();
?>
<?php if ( $a_z_query->have_items() ) : ?>
<?php
$item_count = $a_z_query->get_the_letter_count();
$num_columns = ceil(
$item_count / $_a_z_listing_minpercol
);
?>
<div class="letter-section"
id="<?php $a_z_query->the_letter_id(); ?>">
<h2 class="letter-title">
<span>
<?php $a_z_query->the_letter_title(); ?>
</span>
</h2>
<?php $column_class = "max-$num_columns-columns"; ?>
<ul class="columns <?php echo $column_class; ?>">
<?php
while ( $a_z_query->have_items() ) :
$a_z_query->the_item();
?>
<li>
/** CUSTOMIZED CODE BEGINS */
<?php
$term = $a_z_query->get_the_item_object( 'I understand the issues!' );
if ( 'cross_reference' === $term->taxonomy ) : ?>
<?php $a_z_query->the_title(); ?>:<em> see </em>
<?php echo get_term_meta( $term->term_id, '', false )["target_subjects"][0] ; ?>
<?php else : ?>
<a href="<?php $a_z_query->the_permalink(); ?>">
<?php $a_z_query->the_title(); ?>
</a>
<?php endif ?>
/** CUSTOMIZED CODE ENDS */
</li>
<?php endwhile; ?>
</ul>
<div class="back-to-top">
<a href="#letters">
<?php _e( 'Back to top', 'a-z-listing' ); ?>
</a>
</div>
</div>
<?php
endif;
endwhile;
?>
</div>
</div>
</div>
<?php else : ?>
<p>
<?php
esc_html_e(
'There are no posts included in this index.',
'a-z-listing'
);
?>
</p>
<?php
endif;
-
This reply was modified 3 years, 8 months ago by
pcgardner. Reason: Improved accuracy