Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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:

    1. 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 key field_64a6950720f4e.
    2. 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
    #1412693

    Any ideas, guys?

    #1412899

    Hi,
    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.
    Enfold_Support_2556.jpeg
    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 helps

    Best regards,
    Mike

    #1412925

    Thanks, Mike – I’ll try that. Any pointers on how can I add this code to a child theme.

    #1412926

    PS 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?

    #1412945

    Hi,
    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.
    Enfold_Support_2560.jpeg
    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,
    Mike

    #1412958

    Hi 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

    #1412974

    Hi,
    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,
    Mike

    #1412975

    Thanks, 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.
    Dominic

    #1413040

    Hi,
    Ok, please let us know if this works.

    Best regards,
    Mike

    #1413046

    Hi Mike
    It works – thanks so much for all your help as always! Thrilled with it!

    #1413058

    Hi,
    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

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Using a Custom Field Type on Pages in Post Slider Element’ is closed to new replies.