Tagged: custom field types, post slider element
-
AuthorPosts
-
July 6, 2023 at 1:00 pm #1412612
Hi
I am using Post Slider Elements on a homepage to display hero content from Posts, Pages and Custom Post Types (CPT). See:
https://owe.brother.design/home/home-page-testing/
This allows the client to add new Posts/Pages and control what gets displayed on, and linked to from, the homepage without them having to fiddle with the homepage itself. They do this by simply adding new Posts/Pages and checking a taxonomy item eg. “Insert into tile 1” or “Insert into tile 2“. The Posts/Pages which are checked then automatically appear on the homepage within the appropriate Post Slider Element.
It works really well.
However, I would like the Post Slider Element that displays Pages to display a headline different to that of the Page title.
Eg. using the example above, the tile that reads ‘Vision‘ (that links to the Vision page), I would like the headline to read “Ten guided principles”
I have begun to enable this by:
- adding a custom field to the bottom of the page editor to add an alternative headline. This field has the name
headline_copy_for_homepage_tile
or field keyfield_64a6950720f4e
. - I have also given the Post Slider Element that features/links to Page content its own CSS class of
.homepage-page-slider
to help isolate it from the others
All I need now is the code to query and display the alternative headline.
Anyone know how I can do this? Thanks so much in advance.
- This topic was modified 1 year, 4 months ago by domchocolate. Reason: Typo
- This topic was modified 1 year, 4 months ago by domchocolate. Reason: Typo
- This topic was modified 1 year, 4 months ago by domchocolate. Reason: New URL
July 7, 2023 at 12:56 pm #1412693Any ideas, guys?
July 9, 2023 at 10:04 pm #1412899Hi,
Thanks for your patience, I found that if you edit\enfold\config-templatebuilder\avia-shortcodes\postslider\postslider.php
on line 893 find:
$title = avia_wp_get_the_title( $entry );
and change to
$title = get_post_meta($the_id, 'headline_copy_for_homepage_tile', true);
your title will show your custom field “Ten guided principles”
The only problem is that if the post doesn’t have a custom field no title will show, so I thought that if I add this before the switch( $contents ) on line 880:$meta_value = get_post_meta($the_id, 'headline_copy_for_homepage_tile', true); if ($meta_value == '') { avia_wp_get_the_title( $entry ); }
and then change line 893 to:
$title = $meta_value;
it would show the title if no custom field is there.
but it doesn’t work, only the custom field is shown.
Perhaps this will put you on the right path and you can correct my mistake.
BTW I was only changing the title on line 838 because you are only showing the “title” in the post slider.
I hope this helpsBest regards,
MikeJuly 10, 2023 at 8:55 am #1412925Thanks, Mike – I’ll try that. Any pointers on how can I add this code to a child theme.
July 10, 2023 at 8:58 am #1412926PS I only want to do this to the page .homepage-page-slider post slider element the others need to stay the same.
Perhaps we show both title and custom field and show/hide whichever using CSS? Any ideas around that?
July 10, 2023 at 12:11 pm #1412945Hi,
I found this is the correct code for around line 874 before the switch( $contents ) on line 880:$meta_value = get_post_meta($the_id, 'headline_copy_for_homepage_tile', true); if ($meta_value == '') { $meta_value = avia_wp_get_the_title( $entry ); }
and change line 893 to:
$title = $meta_value;
assuming that your element is set to only show the title.
Now if the item has a headline_copy_for_homepage_tile value then it will show, otherwise the default title will show.
You can add your modified postslider.php to your child theme, by first ensuring that your child theme functions.php has this functions.php:function avia_include_shortcode_template( $paths ) { if( ! is_array( $paths ) ) { $paths = array(); } $template_url = get_stylesheet_directory(); array_unshift( $paths, $template_url . '/shortcodes/' ); return $paths; } add_filter( 'avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1 );
and your child theme directory has the directory /shortcodes/ in it, and then move your modified /postslider/postslider.php into it.
Best regards,
MikeJuly 10, 2023 at 2:25 pm #1412958Hi Mike
That works great. One final question – if you now visit the page you’ll see I’ve got the custom headline (thanks) and I’ve added the original post name as a pseudo-class (:before) in the CSS (added as a code block on the page).
Is there a way of automatically calling the original page title into said pseudo-class content variable (content: ‘vision’) or, alternatively, is there another way of doing this by tweaking the postslider.php further?
I’m just trying to make edits as simple as possible for the client.
Thanks so much, again, for all your help.
Dominic
July 10, 2023 at 6:13 pm #1412974Hi,
I’m not sure why you would want to show the real title and the custom field title at the same time, but I guess you could add the $meta_value to the
$excerpt line 883 instead and then use the Title & Excerpt option in the post slider element.Best regards,
MikeJuly 10, 2023 at 6:18 pm #1412975Thanks, Mike – I’ll try that. It’s so I can have a more advertising-led headline alongside the factual, signpost-type title. It’s about language and hierarchy rather than science. I’ll let you know how I get on.
DominicJuly 11, 2023 at 12:30 pm #1413040July 11, 2023 at 1:28 pm #1413046Hi Mike
It works – thanks so much for all your help as always! Thrilled with it!July 11, 2023 at 5:08 pm #1413058Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike - adding a custom field to the bottom of the page editor to add an alternative headline. This field has the name
-
AuthorPosts
- The topic ‘Using a Custom Field Type on Pages in Post Slider Element’ is closed to new replies.