- This topic has 7 replies, 3 voices, and was last updated 2 years, 4 months ago by Ying.
-
AuthorPosts
-
December 20, 2021 at 1:56 am #2054216Matthias
Hello Team,
first of all thank you for the amazing theme, which we use for a long time now and are extremely happy with.
I know, that my question is out of the scope of your normal duties, however, maybe you can still guide me in the right direction with some code?We use “Simple Author Box Pro” to show information about the author at the end of each article. Example here:
https://demenz.lanaprinzip.com/vergesslichkeit-demenz/As of Google EAT criteria, we would like to show at the beginning of the article not only the name of the author, but also the “Job Title” from the post author plugin.
I am talking abou the line under the post title: “Published 15. Dezember 20217. Changed Juli 2021 von Dr. Silvia Nold”
Basically behind the name should be the job title.The author of SAB told me:
If you are comfortable editing your theme’s code, you can retrieve the Job Title by:$job_title = get_the_author_meta(‘sab_box_job_title’, $author_id);
Hence my question, would you have a snippet code for me?
In CSS I use:/* Display updated date */ .posted-on .updated { display: inline-block; margin-right: 1em; } /*Add date prefixes */ .posted-on .updated:before { content: 'Aktualisiert: '; } .posted-on .entry-date:before { content: 'Veröffentlicht: '; }
Thank you very much,
MatthiasDecember 20, 2021 at 5:14 am #2054363DavidStaffCustomer SupportHi there,
So you could try the following PHP Snippets to filter in your own post meta as explained in this doc:
https://docs.generatepress.com/article/generate_header_entry_meta_items/
For you requirement:
1. Register a new post Meta item:
add_action( 'generate_post_meta_items', function( $item ) { if ( 'job' === $item ) { global $post; $author_id = $post->post_author; $job_title = get_the_author_meta( 'sab_box_job_title', $author_id ); echo $job_title; } } );
2. Then we append our new
job
meta item to the end of the post meta:add_filter( 'generate_header_entry_meta_items', function() { $items[] = 'job'; return $items; } );
December 20, 2021 at 5:55 am #2054398MatthiasHi David,
thank you for your time and response.
I added one Snippet with add_action and add_filter.add_action( 'generate_post_meta_items', function( $item ) { if ( 'job' === $item ) { global $post; $author_id = $post->post_author; $job_title = get_the_author_meta( 'sab_box_job_title', $author_id ); echo $job_title; } } ); add_filter( 'generate_header_entry_meta_items', function() { $items[] = 'job'; return $items; } );
In this case only the Users Title is shown, but the publish and change date, the author name is gone. Did I miss something?
Thank you,
MatthiasDecember 20, 2021 at 11:08 am #2054820YingStaffCustomer SupportHi Matthias,
Try this filter instead:
add_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'author', 'job', ); } );
Let me know 🙂
December 20, 2021 at 11:55 pm #2055210MatthiasHi Ying,
this one works perfectly fine! Thank you.
One last question:Is there a possiblity to have the job displayed between brackets (Job Title)?
Thank you,
MatthiasDecember 21, 2021 at 10:08 am #2055940YingStaffCustomer SupportYes, try to change this PHP snippet:
add_action( 'generate_post_meta_items', function( $item ) { if ( 'job' === $item ) { global $post; $author_id = $post->post_author; $job_title = get_the_author_meta( 'sab_box_job_title', $author_id ); echo $job_title; } } );
to
add_action( 'generate_post_meta_items', function( $item ) { if ( 'job' === $item ) { global $post; $author_id = $post->post_author; $job_title = get_the_author_meta( 'sab_box_job_title', $author_id ); echo '('.$job_title.')'; } } );
Let me know 🙂
December 21, 2021 at 11:00 am #2055979MatthiasHi Ying,
WONDERFUL! Thank you 🙂 It works perfectly fine…
All the best,
MatthiasDecember 21, 2021 at 12:08 pm #2056032YingStaffCustomer SupportYou are welcome Matthias 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.