Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1305128

    Enfold team, hello.
    Here’s an interesting twist. Would it be possible to display the “You Might Also Like” related content in the sidebar as a widget rather than at the bottom of a post?

    Thanks for your insight.
    j

    #1305474

    Hey Julie,
    Thank you for your patience, unfortunately, you can not do this typically, but you could try this with a custom shortcode and some custom CSS. First, try adding this code to the end of your functions.php file in Appearance > Editor:

    function related_posts_shortcode( $attr ) {
        ob_start();
        get_template_part( 'includes/related-posts' );
        return ob_get_clean();
    }
    add_shortcode( 'rpost', 'related_posts_shortcode' );

    I recommend using a child theme
    add_shortcode_to_child_theme.jpg
    Then add a Custom HTML widget to your sidebar and use this shortcode: [rpost]
    shortcode_in_custom_html_widget.jpg
    Then add this css to your child theme stylesheet, or theme Quick CSS area:

    .widget_custom_html > .custom-html-widget > .related_posts {
    	padding: 23px 0 0 0;
    }
    #top .widget_custom_html > .custom-html-widget > .related_posts > .related_entries_container > .related_column {
        width: 100%;
    }
    #top main > .related_posts {
    	display: none;
    }
    

    add_shortcode_css_to_child_theme.jpg
    Please note that the last rule is to hide the regular related posts element from your posts.
    Expected results:
    related_posts_in_sidebar_widget.jpg

    Best regards,
    Mike

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.