- This topic has 5 replies, 3 voices, and was last updated 1 year, 9 months ago by Fernando.
-
AuthorPosts
-
June 6, 2022 at 1:28 pm #2245454Laurent
Hi,
I’m trying to add the “Featured Image” function for categories.
I have followed the explanations here:
https://generatepress.com/forums/topic/how-do-i-get-the-header-on-the-category-pages/#post-1440100
https://generatepress.com/forums/topic/advance-custom-field-image-for-my-category-archive-header-element-background/#post-1492195Here are some screenshots of what I did:
[url=https://postimg.cc/GBFCB51V][img]https://i.postimg.cc/GBFCB51V/screenshot-dev-chantdescailles-be-2022-06-06-22-22-59.png[/img][/url] [url=https://postimg.cc/gLJFTc6b][img]https://i.postimg.cc/gLJFTc6b/screenshot-dev-chantdescailles-be-2022-06-06-22-23-51.png[/img][/url] [url=https://postimg.cc/1nyZDrmt][img]https://i.postimg.cc/1nyZDrmt/screenshot-dev-chantdescailles-be-2022-06-06-22-24-16.png[/img][/url] [url=https://postimg.cc/5YpWgQym][img]https://i.postimg.cc/5YpWgQym/screenshot-dev-chantdescailles-be-2022-06-06-22-25-07.png[/img][/url]Do you understand what I have to do to make the image appear near the category title?
Thank you in advance for your answer.
See you soon,June 6, 2022 at 2:27 pm #2245478LeoStaffCustomer SupportHi there,
Not sure if I fully understand the question. Featured images (WP core function) can only be added to static pages and posts and not to archives/blogs.
Would this video be helpful?
Let me know 🙂
June 6, 2022 at 10:24 pm #2245667LaurentHello Leo,
Thanks for the video but I already know this. This is not what I need to do now.
I would like to do exactly the same as Samantha explains here: https://generatepress.com/forums/topic/advance-custom-field-image-for-my-category-archive-header-element-background/#post-1438791
I have followed all the explanations but without success.
I think Elvin has the solution but I don’t know how to contact him.
Thanks in advance.
Have a nice day,June 6, 2022 at 11:10 pm #2245691Fernando Customer SupportHi Laurent,
Are you using a Header Element or a Block Element – Page Hero?
Perhaps you can provide a link to the site in question?
If you’re using a Page Hero, you may create a custom portable hook with a shortcode through adding this PHP:
function your_shortcode($atts, $content = null) { ob_start(); do_action('hook_name'); return ob_get_clean(); } add_shortcode('portable_hook', 'your_shortcode');
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Then, you may add shortcode [portable_hook] hook to a Shortcode Block.
Then, you may add this code through a Hook Element hooked to Custom Hook – hook_name:
<?php $term = get_queried_object(); $image = get_field('myimage', get_queried_object() ); if( $image ) { echo '<img src="'. $image . '">'; } ?>
Kindly replace
myimage
with your field name.Example: https://share.getcloudapp.com/NQulvR41
See: https://share.getcloudapp.com/kpu8m1OR
Also see image appearing: https://share.getcloudapp.com/DOudvnkd
This should make the image appear wherever you want. The return format of the image should be image URL int the custom field settings.
Kindly let us know.
June 7, 2022 at 1:52 pm #2246547LaurentHi Fernando,
Thank you very much for your reply but I can’t answer your question.
Here is the address of the category where I am trying to post the image:
https://ouvaton.link/hRAv8FDo you know how to find the answer to your question only by checking the page?
Thank you very much in advance.
Good evening,June 7, 2022 at 5:36 pm #2246611Fernando Customer SupportI see. Thank you for adding the link to your site.
If that’s the case, can you try creating a Hook Element.
1. Add this code in the hook element:
<?php $term = get_queried_object(); $image = get_field('myimage', $term ); if( $image ) { echo '<img src="'. $image . '">'; } ?>
Replace
myimage
with your field name for the image. The return format of the image field should be image URL.2. Set the hook to generate_after_archive_title
3. check “Execute PHP”
4. Set the display rule location to Post Category Archive then choose the appropriate archive.Example: https://share.getcloudapp.com/qGuODBoj
Also see: https://share.getcloudapp.com/mXuxmzqj
Kindly let us know how it goes!
-
AuthorPosts
- You must be logged in to reply to this topic.