Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1352645

    Hi, I’m using the Blog Post widget within Enfold to show all our blog posts using the Grid Layout. We are currently showing the “Title and Excerpt + Read More Link” layout option. We would like to add a listing of all tags that are associated with each post underneath the blog post title. Here’s an example of what I would like to see

    blog post title 1 blog post title 2 blog post title 3
    tag 1, tag 2, tag 3 tag 2, tag 5 tag 6
    Excerpt Excerpt Excerpt
    Read More Read More Read More

    Is it possible to display each related tag for each post within this widget? I only want to show the tags that are related and sometimes there might be many associated tags for a post. Some posts may just have one though.

    Thoughts? Thanks!

    #1352716

    Hey CodeSamurai,

    Thank you for the inquiry.

    Did you set the Blog Style to Grid Layout? If so, try to use this filter in the functions.php file to insert the tags before the excerpt.

    
    function new_avf_post_slider_entry_excerpt($excerpt, $prepare_excerpt, $permalink, $entry ) {
        $tags_output = "";
        $tags = get_the_tags($entry->ID);
       
        foreach ( $tags as $tag ) {
            $tags_output .= "<a href='" . get_tag_link( $tag->term_id ) . "'>" . $tag->name . "</a>";
        }
    
        $excerpt = $tags_output . "<br>" $excerpt;
    
         return $excerpt;
    }
    add_filter('avf_post_slider_entry_excerpt', 'new_avf_post_slider_entry_excerpt', 10, 4);
    

    Best regards,
    Ismael

    #1352779

    Hi Ismael, thank you for the assistance. We are really close, but it’s not quite right yet. With the code that was provided every blog post lists the exact same tags underneath each blog post title instead of just the tags associated with the corresponding post. For example, “blog post title #1” should have “Tag 1”, “Tag 2”, “Tag 3” whereas “blog post title #2 should have “Tag 2, “Tag 3” and then “blog post title #3 should have “Tag 5” only. Instead of just showing the associated tags for each post, all blog posts are showing the exact same tags underneath each blog post title. I’m just listing dummy text as an example, but hopefully you get the idea.

    Any thoughts on how to get only the associated tags to appear underneath the corresponding blog post title instead of just showing all tags? Thanks!

    #1352864

    Hi,

    Thank you for the update.

    We adjusted the code a bit and replace get_tags with the get_the_tags function. This should now display tags that are actually associated with a specific post.

    // https://developer.wordpress.org/reference/functions/get_the_tags/

    Best regards,
    Ismael

    #1352874

    isn’t there a dot missing?

    $excerpt = $tags_output . "<br>" . $excerpt;
    
    #1353457

    please consider the next post.

    #1353458

    And – wouldn’t it be better placed on meta-content with filter: avf_post_slider_meta_content
    because the above influences as part of it : the excerpt length

    #1353460

    and if you like to show this only if you have set on enfold-child – blog layout – blogpost meta elements : Blog Post Tags to show.

    function new_avf_post_slider_meta_content($meta_content, $entry, $index, ) {
        $tags = get_the_tags($entry->ID);
        $tags_output = "";
        if('blog-meta-tag' == avia_get_option('blog-meta-tag') && $tags ){
            $tags_output .= '<div class="post-tags" style="display:block"><p class="post-tags-inner">';
            foreach ( $tags as $tag ) {
                $tags_output .= '<a href="  '.get_tag_link( $tag->term_id ).'  ">';
                $tags_output .= '<strong> '.$tag->name.' </strong>';
                $tags_output .= '</a>' ;
                if(next($tags)){
                    $tags_output .= '<span class="text-sep"> | </span>' ;
                }
            }
            $tags_output .= '<br></p></div>';
            $meta_content = $tags_output . $meta_content;
        };
        return $meta_content;
    }
    add_filter('avf_post_slider_meta_content', 'new_avf_post_slider_meta_content', 10, 4);

    Of course, you can also use other separators there …

    if(next($tags)){
         $tags_output .= '<span class="text-sep"> , </span>' ;
    }

    https://webers-testseite.de/blog-seite/

    #1353505

    PS: if you like to move the tags to f.e. under the title:
    this behind that function above

    
    // this to move that tags in the DOM
    function move_position_of_post_tags(){
    ?>
    <script type="text/javascript">
    (function($) {
    $(document).ready(function(){    
        $('.post-tags').each( function() {
            var target = $(this).closest('.slide-entry').find('.slide-entry-title');
            $(this).insertAfter($(target)).css('text-align','center');
        });
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'move_position_of_post_tags');

    then example page would look like this

    (PS – i see that i got on my test environment some special settings for that in quick css. – maybe a padding-bottom for slide-content will be necessary on that:

    #top.blog .slide-content {
      padding-bottom: 50px;
    }
    #1353508

    it works for blog alb pages and for blog page ( set on enfold-child – theme options – “And where do you want to display the Blog?” ) if this is a page showing posts ( not portfolios )
    So let this options free ( not selected ) – then it will work everywhere

    PS :
    i do not know why ismaels code does work this way – i got that on the beginning too – that only one of those tags is shown – and the rest not. ( if i insert it now – there are all tags – but in a line – don’t know if he changed the code above )
    All queries match mine (or vice versa). Also the each loop should work. I only added some surrounding containers, a separator and a condition to be fullfilled – and the filter to use to place the tags on a different location.

    you can change his code the way i did with some surroundings etc. and that condition.:

    function new_avf_post_slider_entry_excerpt($excerpt, $prepare_excerpt, $permalink, $entry ) {
        $tags = get_the_tags($entry->ID);
        $tags_output = "";
        if('blog-meta-tag' == avia_get_option('blog-meta-tag') && $tags ){
            $tags_output .= '<div class="post-tags" style="display:block"><p class="post-tags-inner">';
            foreach ( $tags as $tag ) {
                $tags_output .= '<a href="  '.get_tag_link( $tag->term_id ).'  ">';
                $tags_output .= '<strong> '.$tag->name.' </strong>';
                $tags_output .= '</a>' ;
                if(next($tags)){
                    $tags_output .= '<span class="text-sep"> | </span>' ;
                }
            }
            $tags_output .= '<br></p></div>';
            $excerpt = $tags_output . $excerpt;
        };
        return $excerpt;
    }
    add_filter('avf_post_slider_entry_excerpt', 'new_avf_post_slider_entry_excerpt', 10, 4);

    you got the choice

    #1353566

    Hi Ismael, I am good to go on this one. The code update to use get_the_tags works for me. I just needed a listing of all tags within the Blog Layout widget and that did the trick.

    I know there is a different conversation going related to blogs and I’m not sure the status, but my initial question has been answered at least. Thank you for the help!

    #1354246

    Hi,
    Glad to hear that Guenni007 & Ismael were able to assist with a solution, we will leave this open should they have anything else for each other.
    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)
  • You must be logged in to reply to this topic.