Additional custom taxonomy
-
Hello,
I use subtitles for woocommerce products and would like to output them in the listing as “[TITLE] – [SUBTITLE]”. The subtitle is registered taxonomy. Is that possible?
Thank you!
MartinThe page I need help with: [log in to see the link]
-
Hello,
Thank you for using AlphaListing. Yes, it’s definitely possible to display the subtitle (in your case, a registered taxonomy) in the format “[TITLE] – [SUBTITLE]” by customizing the listing template.
To do this, you can copy the filetemplates/a-z-listing.phpfrom the plugin directory into your theme’s root directory and name ita-z-listing.php. That custom template will allow you to modify how each product is displayed.Within the template, you’ll find a loop like this:
<?php
while ( $a_z_query->have_items() ) :
$a_z_query->the_item(); ?>
<li>
<a href="<?php $a_z_query->the_permalink(); ?>">
<?php $a_z_query->the_title(); ?>
</a>
</li>
<?php endwhile; ?>Inside that loop, you can use the
$a_z_query->get_the_item_id()helper to get the product/post ID, and then use WordPress’sget_the_terms()function to retrieve the subtitle taxonomy and output it alongside the title. This gives you the flexibility to format each item exactly how you described.Hello Ethan,
I am sorry, I think I worded it incorrectly: by “registered” I did not mean taxonomy that is a post type (like attributes, or tags), but a custom field (wc_ps_subtitle: [text value]) that is attributed to products.
Thank you!
Martin
Hello Martin,
The same approach can be applied. A custom field in WordPress is saved as post meta (or metadata), so instead of using
get_the_terms(), you would use theget_post_meta()function to retrieve the custom field value.You mentioned you’re using WooCommerce for products. While I’m not deeply familiar with WooCommerce, it appears that it uses the same custom field mechanism as WordPress, so
get_post_meta()should work just fine. If it doesn’t return the expected value, it might be worth checking WooCommerce’s documentation to see if they handle their custom fields differently or provide any specific helper functions to retrieve the custom field value.Best regards,
Ethan
Hello Ethan,
thank you again for your help! Now coming back to this topic after quite some time. As a reminder, I would like to do is output product titles with subtitles in the format [TITLE] – [SUBTITLE]. The subtitle would be a woocommerce custom field named wc_ps_subtitle,
I have tried to adapt the loop like you suggested, but could not get it going. This is my version:
<?php
while ( $a_z_query->have_items() ) :
$a_z_query->the_item();
$post_id = get_the_ID(); // Current product/post ID
$subtitle = get_post_meta( $post_id, 'wc_ps_subtitle', true );
?>
<li>
<a href="<?php $a_z_query->the_permalink(); ?>">
<?php
$a_z_query->the_title();
if ( ! empty( $subtitle ) ) {
echo ' - ' . esc_html( $subtitle );
}
?>
</a>
</li>
<?php endwhile; ?>I use the shortcode
[alphalisting post-type="product"]That’s the list of products only with the (main) titles but without subtitles attached.
https://www.pflanzkompass.at/pflanzen-a-z/
Do you have any suggestions of what needs to be corrected?
Best regards
Martin
Hi Martin,
Try replacing
get_the_ID()with$a_z_query->get_the_item_id()in the loop. Theget_the_ID()function only works in the standard WordPress query loop. In this case, it does not work because the$a_z_queryloop only looks like the standard loop, but it is not the same.Best,
Ethan
Hi Ethan,
great, that works now, thank you!
One little tangent – is there a way to stretch the columns to full page width? They are crowded to the left. The break into 3 columns after a certain amount of entries is fine.
I couldn’t find a solution in the documentation or tickets.
Best regards
Martin
-
This reply was modified 3 months, 1 week ago by
Martin Freisinger.
Hi Martin,
Yes, there are options available to change the number of columns, column width, and column gap. If you are using the Gutenberg (block) editor, those options are presented in the AlphaListing’s block settings. If you are using the shortcode, the following attributes are available:
columns,column-width, andcolumn-gap.columns: controls the target number of columns for the rendered list.- Default value:
3. - Accepts numeric values.
- The rendered layout uses the CSS
min()function to clamp the actual column count based on the user-specified value. That is, the layout won’t always render exactly the number of requested columns, but instead, the CSSmin()function ensures the actual column count is capped by what can realistically fit, so the final layout is the smaller of the user’s request and the available space.
- Default value:
column-width: sets the desired width for each column in the rendered list.- Default value:
15em. - Accepts any CSS length unit (such as
px,em,rem,%, etc.).
- Default value:
column-gap: controls the spacing between columns in the rendered list.- Default value:
0.6em. - Accepts any CSS length unit as well.
- Default value:
You are not required to use those attributes to adjust the layout, and you may need to play with different numbers to get the spacing you want. You can always override the listing’s style using any custom CSS.
Also, if you want to limit the number of items per column, at the moment, the only way to do it is to add and set
$a_z_listing_minpercolvariable to your desired number of items per column at top of the listing’s custom template file.Best,
EthanHi Ethan,
than you very much! The column-width does the job.
Just a note, when using em the column count responses correctly to 1 on mobile, however with % it does not and the 3 columns remain on mobile. For me, em is alright.
Very nice plugin, and great support!
Best regards
Martin
Hi Martin,
Glad to hear everything worked out. Thank you for using AlphaListing!
Best,
Ethan
-
This reply was modified 3 months, 1 week ago by
You must be logged in to reply to this topic.