Home › Forums › Guestbook Add-On › Alternate ways to display additional fields (from the add-on)
- This topic has 3 replies, 2 voices, and was last updated 3 years ago by Marcel Pol.
-
AuthorPosts
-
22 August 2021 at 18:09 #1504Aleksandr KlyashitskyParticipant
I am looking to display the field ‘year visited’ and ‘cottage’ in the header sentence, the one that says ‘Alex from CITY wrote on August 22, 2021 at 7:17 pm’ I would like instead to change it to ‘Alex from CITY stayed in COTTAGE during YEAR wrote’
Can this be achieved? If not, what options do I have with regards to display of alternate fields? Displaying them at the top of the entry or at the bottom, or in the metabox is very limiting.
25 August 2021 at 14:36 #1509Marcel PolKeymasterHi Aleksandr,
No problem about asking this. The 3 options for display are the most common ways for displaying. It can be changed and customized, but often that needs custom code for that specific desire/need.What I did is disable the date fields and also the City/Origin field in the read-settings.
Then this next code can go to a custom plugin, or can be added to the functions.php of your theme.
You might want to check if the slugs of both fields are correct.function gwolle_gb_author_name_html_add_meta_from_addon( $html, $entry ) { if ( ! function_exists( 'gwolle_gb_addon_get_meta_for_preview' ) ) { return $html; } $origin = $entry->get_author_origin(); if ( strlen(str_replace(' ', '', $origin)) > 0 ) { $html .= ' <span class="gb-author-origin"> <span class="gb-author-origin-from-text"> ' . /* translators: city or origin */ esc_html__('from', 'gwolle-gb') . '</span> <span class="gb-author-origin-text"> ' . gwolle_gb_sanitize_output($origin) . '</span> </span>'; } $cottage = gwolle_gb_addon_get_meta_for_preview( $entry->get_id(), 'cottage' ); if ( ! $cottage ) { $cottage = gwolle_gb_addon_get_meta( $entry->get_id(), 'cottage' ); } $year = gwolle_gb_addon_get_meta_for_preview( $entry->get_id(), 'year-visited' ); if ( ! $year ) { $year = gwolle_gb_addon_get_meta( $entry->get_id(), 'year-visited' ); } if ( strlen($cottage) > 0 ) { $html .= '<span class="gb-author-cottage-text"> stayed in ' . $cottage . '</span>'; } if ( strlen($year) > 0 ) { $html .= '<span class="gb-author-cottage-text"> during ' . $year . ' wrote</span>'; } var_dump($html); return $html; } add_filter( 'gwolle_gb_author_name_html', 'gwolle_gb_author_name_html_add_meta_from_addon', 10, 2 );
Does it work for you?
27 August 2021 at 17:50 #1517Aleksandr KlyashitskyParticipantHi Marcel, thanks a lot for your help. The function works well. All I needed to do was disable the city and datetime display before enabling the function, as well as delete the var_dump($html). Thanks again!
28 August 2021 at 09:32 #1518Marcel PolKeymasterOuch, yes, I forgot the
var_dump( $html )
, sorry about that :)Good that it works for you.
-
AuthorPosts
- You must be logged in to reply to this topic.