Okay
  Public Ticket #3679529
Related Posts html tag
Closed

Comments

  •  2
    julien1811 started the conversation

    Hello, 

    I would like to change the html tag of the Related Posts title on my article pages like this one : https://www.duonext.com/avis-dexpert/respect-norme-ifrs16/

    I would like to have a regular <p> instead of a <h3>. Can you tell me which file I need to edit in the theme to change this tag ? I'm using Filezilla

    Wordpress 6.5.5
    Salient 14.0.2

    Best regards, 
    Julien 

    Attached files:  duonext-related-posts.png

  •  1,919
    Judith replied

    Hi Julien,

    Thanks for writing back.

    Unfortunately, we currently don't have a way to change the HTML tags .

    This would require some extensive customization which I'm afraid we are not able to offer due to support scope limitations.

    However, we are partnered with a trusted provider of expert-level Salient customization. If you are interested in initiating a project, we recommend referring to our guide at the following link: https://themenectar.com/salient/customization/

    In the meantime, please don't hesitate to reach out with further questions. We're happy to help.

  •  2
    julien1811 replied

    Hello Judith,

    Thank you for your answer, but I'm afraid that hiring an expert team in order to change an html tag doesn't really make sens to me. I just need a little help finding the file in which the tag is written, and i'll do the job. Is there anybody in the support team which is able to answer this question ? 

    I bought a ~50$ extra support a few month ago in order to have small tips like the one i'm asking ;) 

  •  8,939
    Tahir replied

    Hey Again,

    Add the below code to the Child Theme "functions.php" File and adjust/amend as needed .

    function nectar_related_post_display() {
             global $post;
             global $nectar_options;
             $using_related_posts = ( ! empty( $nectar_options['blog_related_posts'] ) && $nectar_options['blog_related_posts'] === '1' ) ? true : false;
             if ( $using_related_posts === false ) {
                 return;
             }
             $related_functionality = ( isset( $nectar_options['blog_related_posts_functionality'] ) ) ? $nectar_options['blog_related_posts_functionality'] : 'default';
             $current_categories = get_the_category( $post->ID );
             if ( $current_categories ) {
                 $category_ids = array();
                 foreach ( $current_categories as $individual_category ) {
                     $category_ids[] = $individual_category->term_id;
                 }
                 $relatedBlogPosts = array(
                     'category__in'        => $category_ids,
                     'post__not_in'        => array( $post->ID ),
                     'showposts'           => 3,
                     'ignore_sticky_posts' => 1,
                 );
                 // random same cat
                 if ( $related_functionality === 'random_same_cat' ) {
                     $relatedBlogPosts['orderby'] = 'rand';
                 }
                 elseif ( $related_functionality === 'random' ) {
                    // random in any cat
                     $relatedBlogPosts['orderby'] = 'rand';
                     unset( $relatedBlogPosts['category__in'] );
                 }
                 $related_posts_query = new WP_Query( $relatedBlogPosts );
                 $related_post_count  = $related_posts_query->post_count;
                 if ( $related_post_count < 2 ) {
                    
                    // switch to all posts.
                    $relatedBlogPosts = array(
                        'post_type'           => 'post',
                        'orderby'             => 'rand',
                        'post__not_in'        => array( $post->ID ),
                        'showposts'           => has_action('nectar_blog_loop_post_item') ? 4 : 3,
                        'ignore_sticky_posts' => 1,
                    );
       
                    $related_posts_query = new WP_Query( $relatedBlogPosts );
                    $related_post_count  = $related_posts_query->post_count;
                    if( $related_post_count < 2 ) {
                        return;
                    }
                 }
                 $span_num = ( $related_post_count == 2 ) ? 'span_6' : 'span_4';
                 $related_title_text        = nectar_get_related_post_title();
                 $related_post_title_option = ( ! empty( $nectar_options['blog_related_posts_title_text'] ) ) ? wp_kses_post( $nectar_options['blog_related_posts_title_text'] ) : __('Related Posts','salient');
                 $hidden_title_class = null;
                 if ( $related_post_title_option === 'hidden' ) {
                     $hidden_title_class = 'hidden';
                     $related_title_text = esc_html__( 'Related Posts', 'salient' );
                 }
                 $using_post_pag       = ( ! empty( $nectar_options['blog_next_post_link'] ) && $nectar_options['blog_next_post_link'] === '1' ) ? 'true' : 'false';
                 $related_post_style   = ( ! empty( $nectar_options['blog_related_posts_style'] ) ) ? esc_html( $nectar_options['blog_related_posts_style'] ) : 'material';
                 $related_post_excerpt = ( isset( $nectar_options['blog_related_posts_excerpt'] ) && '1' === $nectar_options['blog_related_posts_excerpt'] ) ? true : false;
                 
                 $global_lazy_load = false;
                 if( property_exists('NectarLazyImages', 'global_option_active') && true === NectarLazyImages::$global_option_active ) {
                     $global_lazy_load = true;
                 }
                 
                 if( !has_action('nectar_blog_loop_post_item') ) {
                    $related_title_class = apply_filters('nectar_related_posts_title_class', 'related-title');
                    echo '<div class="row vc_row-fluid full-width-section related-post-wrap" data-using-post-pagination="' . esc_attr( $using_post_pag ) . '" data-midnight="dark"> <div class="row-bg-wrap"><div class="row-bg"></div></div> <h3 class="'. $related_title_class .' ' . $hidden_title_class . '">' . wp_kses_post( $related_title_text ) . '</h3><div class="row span_12 blog-recent related-posts columns-' . esc_attr( $related_post_count ) . '" data-style="' . esc_attr( $related_post_style ) . '" data-color-scheme="light">';
                    if ( $related_posts_query->have_posts() ) :
                        while ( $related_posts_query->have_posts() ) :
                            $related_posts_query->the_post();
                            ?>
                            <div class="col <?php echo esc_attr( $span_num ); ?>">
                                <div <?php="" post_class(="" 'inner-wrap'="" );="" ?="">>
                                    <?php
                                    if ( has_post_thumbnail() ) {
                                        $related_image_size = ( $related_post_count == 2 ) ? 'wide_photography' : 'portfolio-thumb';
                                        
                                        echo '<a href="' . esc_url( get_permalink() ) . '" class="img-link"--><span class="post-featured-img">';
                                        
                                        if( true === $global_lazy_load ) {
                                            
                                            $image_src = get_the_post_thumbnail_url($post->ID, $related_image_size);
                                            $image_id  = get_post_thumbnail_id($post->ID);
                                            
                                            if( $image_src && $image_id ) {
                                                
                                            $image_width = ( 'wide_photography' === $related_image_size ) ? '900' : '600';
                                            $image_height = ( 'wide_photography' === $related_image_size  ) ? '600' : '403';
                                                    
                                                $wp_img_alt_tag = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
                                                    
                                                $image_attrs_escaped = 'height="'.esc_attr($image_height).'" ';
                                            $image_attrs_escaped .= 'width="'.esc_attr($image_width).'" ';
                                                $image_attrs_escaped .= 'alt="'.esc_attr($wp_img_alt_tag).'" ';
                                                $image_attrs_escaped .= 'data-nectar-img-src="'.esc_url($image_src).'" ';
                                                
                                                $placeholder_img_src = "data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%20".esc_attr($image_width).'%20'.esc_attr($image_height)."'%2F%3E";
                                                
                                                echo '<img class="nectar-lazy skip-lazy" '.$image_attrs_escaped.'="" src="'.$placeholder_img_src.'">';
                                            }
                                            
                                        } else {
                                            echo get_the_post_thumbnail( $post->ID, $related_image_size, array( 'title' => '' ) ); 
                                        }
                                        
                                        echo '</span>';
                                    }
                                    ?>
                                    <?php
                                    echo '<span class="meta-category"-->';
                                    $categories = get_the_category();
                                    if ( ! empty( $categories ) ) {
                                        $output = null;
                                        foreach ( $categories as $category ) {
                                            $output .= '<a class="' . esc_attr( $category->slug ) . '" href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
                                        }
                                        echo trim( $output );
                                    }
                                    echo '';
                                    ?>
                                    <a class="entire-meta-link" href="<?php the_permalink(); ?>" aria-label="<?php echo get_the_title(); ?>"></a>
                                    <div class="article-content-wrap">
                                        <div class="post-header">
                                            <span class="meta">
                                                <!--?php
                                                if ( $related_post_style != 'material' ) {
                                                    echo get_the_date();
                                                }
                                                ?>
                                            </span>
                                            <h3 class="title"><!--?php the_title(); ?--></h3>
                                            <!--?php if( true === $related_post_excerpt ) {
                                                // Excerpt.
                                                $excerpt_length = ( ! empty( $nectar_options['blog_excerpt_length'] ) ) ? intval( $nectar_options['blog_excerpt_length'] ) : 15;
                                        echo '<div class="excerpt"-->';
                                        echo nectar_excerpt( $excerpt_length );
                                        echo '</div>';
                                            } ?>
                                        </div><!--/post-header-->
                                        <!--?php
                                        if ( function_exists( 'get_avatar' ) && $related_post_style === 'material' ) {
                                            echo '<div class="grav-wrap"-->' . get_avatar( get_the_author_meta( 'email' ), 70, null, get_the_author() ) . '<div class="text"> <a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>' . get_the_date() . '</div></div>';
                                        }
                                        ?>
                                    </div>
                                    <!--?php if ( $related_post_style != 'material' ) { ?-->
                                        <div class="post-meta">
                                            <span class="meta-author"> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"> <i class="icon-default-style icon-salient-m-user"></i> <!--?php the_author(); ?--></a> </span>
                                            <!--?php if ( comments_open() ) { ?-->
                                                <span class="meta-comment-count">  <a href="<?php comments_link(); ?>">
                                                    <i class="icon-default-style steadysets-icon-chat-3"></i> <!--?php comments_number( '0', '1', '%' ); ?--></a>
                                                </span>
                                            <!--?php } ?-->
                                        </div>
                                        <!--?php
                                    }
                                    ?-->
                                </div>
                            </div>
                            <!--?php
                        endwhile;
                    endif;
                    echo '</div-->';
                }
                else {
                    $related_title_class = apply_filters('nectar_related_posts_title_class', 'related-title');
                    echo '<div class="row vc_row-fluid full-width-section related-post-wrap post-loop-builder" data-midnight="dark">';
                    $related_title_text = nectar_get_related_post_title();
                    if ($related_title_text !== 'hidden' && $related_post_count > 1 ) {
                        echo '<h3 class="'.$related_title_class.'">' . wp_kses_post( $related_title_text ) . '</h3>';
                    }
                    do_action('nectar_before_blog_loop_content');
                    if ( $related_posts_query->have_posts() ) : while ( $related_posts_query->have_posts() ) : $related_posts_query->the_post();
                        do_action('nectar_blog_loop_post_item');
                        endwhile;
                    endif;
                    do_action('nectar_after_blog_loop_content');
                    echo '</div>';
                    
                }
                 wp_reset_postdata();
             }// if has categories
            }
    

    Thanks.


    ThemeNectar Support Team 

  •  2
    julien1811 replied

    Thanks a lot, it seems to be what i was looking for.
    It's indeed a little bit more complicated than changing an html tag ! 

    Anyway, I found the part which was interesting me but the code doesn't seem to be working as I got an fatal error as soon as I update my function.php file. 



    I changed the <h3> for a <p> 

    <p class="title"><?php the_title(); ?></p>

    and un-commenting the part of the code which was commented. But there is a line which seems to contain an error in the code you sent me : 

     <div <?php="" post_class(="" 'inner-wrap'="" );="" ?="">>

    Here is the full code without the inital comments : 

    function nectar_related_post_display() {
             global $post;
             global $nectar_options;
             $using_related_posts = ( ! empty( $nectar_options['blog_related_posts'] ) && $nectar_options['blog_related_posts'] === '1' ) ? true : false;
             if ( $using_related_posts === false ) {
                 return;
             }
             $related_functionality = ( isset( $nectar_options['blog_related_posts_functionality'] ) ) ? $nectar_options['blog_related_posts_functionality'] : 'default';
             $current_categories = get_the_category( $post->ID );
             if ( $current_categories ) {
                 $category_ids = array();
                 foreach ( $current_categories as $individual_category ) {
                     $category_ids[] = $individual_category->term_id;
                 }
                 $relatedBlogPosts = array(
                     'category__in'        => $category_ids,
                     'post__not_in'        => array( $post->ID ),
                     'showposts'           => 3,
                     'ignore_sticky_posts' => 1,
                 );
                 // random same cat
                 if ( $related_functionality === 'random_same_cat' ) {
                     $relatedBlogPosts['orderby'] = 'rand';
                 }
                 elseif ( $related_functionality === 'random' ) {
                    // random in any cat
                     $relatedBlogPosts['orderby'] = 'rand';
                     unset( $relatedBlogPosts['category__in'] );
                 }
                 $related_posts_query = new WP_Query( $relatedBlogPosts );
                 $related_post_count  = $related_posts_query->post_count;
                 if ( $related_post_count < 2 ) {
                    
                    // switch to all posts.
                    $relatedBlogPosts = array(
                        'post_type'           => 'post',
                        'orderby'             => 'rand',
                        'post__not_in'        => array( $post->ID ),
                        'showposts'           => has_action('nectar_blog_loop_post_item') ? 4 : 3,
                        'ignore_sticky_posts' => 1,
                    );
       
                    $related_posts_query = new WP_Query( $relatedBlogPosts );
                    $related_post_count  = $related_posts_query->post_count;
                    if( $related_post_count < 2 ) {
                        return;
                    }
                 }
                 $span_num = ( $related_post_count == 2 ) ? 'span_6' : 'span_4';
                 $related_title_text        = nectar_get_related_post_title();
                 $related_post_title_option = ( ! empty( $nectar_options['blog_related_posts_title_text'] ) ) ? wp_kses_post( $nectar_options['blog_related_posts_title_text'] ) : __('Related Posts','salient');
                 $hidden_title_class = null;
                 if ( $related_post_title_option === 'hidden' ) {
                     $hidden_title_class = 'hidden';
                     $related_title_text = esc_html__( 'Related Posts', 'salient' );
                 }
                 $using_post_pag       = ( ! empty( $nectar_options['blog_next_post_link'] ) && $nectar_options['blog_next_post_link'] === '1' ) ? 'true' : 'false';
                 $related_post_style   = ( ! empty( $nectar_options['blog_related_posts_style'] ) ) ? esc_html( $nectar_options['blog_related_posts_style'] ) : 'material';
                 $related_post_excerpt = ( isset( $nectar_options['blog_related_posts_excerpt'] ) && '1' === $nectar_options['blog_related_posts_excerpt'] ) ? true : false;
                 
                 $global_lazy_load = false;
                 if( property_exists('NectarLazyImages', 'global_option_active') && true === NectarLazyImages::$global_option_active ) {
                     $global_lazy_load = true;
                 }
                 
                 if( !has_action('nectar_blog_loop_post_item') ) {
                    $related_title_class = apply_filters('nectar_related_posts_title_class', 'related-title');
                    echo '<div class="row vc_row-fluid full-width-section related-post-wrap" data-using-post-pagination="' . esc_attr( $using_post_pag ) . '" data-midnight="dark"> <div class="row-bg-wrap"><div class="row-bg"></div></div> <h3 class="'. $related_title_class .' ' . $hidden_title_class . '">' . wp_kses_post( $related_title_text ) . '</h3><div class="row span_12 blog-recent related-posts columns-' . esc_attr( $related_post_count ) . '" data-style="' . esc_attr( $related_post_style ) . '" data-color-scheme="light">';
                    if ( $related_posts_query->have_posts() ) :
                        while ( $related_posts_query->have_posts() ) :
                            $related_posts_query->the_post();
                            ?>
                            <div class="col <?php echo esc_attr( $span_num ); ?>">
                                <div <?php="" post_class(="" 'inner-wrap'="" );="" ?="">>
                                    <?php
                                    if ( has_post_thumbnail() ) {
                                        $related_image_size = ( $related_post_count == 2 ) ? 'wide_photography' : 'portfolio-thumb';
                                        
                                        echo '<a href="' . esc_url( get_permalink() ) . '" class="img-link"><span class="post-featured-img">';
                                        
                                        if( true === $global_lazy_load ) {
                                            
                                            $image_src = get_the_post_thumbnail_url($post->ID, $related_image_size);
                                            $image_id  = get_post_thumbnail_id($post->ID);
                                            
                                            if( $image_src && $image_id ) {
                                                
                                            $image_width = ( 'wide_photography' === $related_image_size ) ? '900' : '600';
                                            $image_height = ( 'wide_photography' === $related_image_size  ) ? '600' : '403';
                                                    
                                                $wp_img_alt_tag = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
                                                    
                                                $image_attrs_escaped = 'height="'.esc_attr($image_height).'" ';
                                            $image_attrs_escaped .= 'width="'.esc_attr($image_width).'" ';
                                                $image_attrs_escaped .= 'alt="'.esc_attr($wp_img_alt_tag).'" ';
                                                $image_attrs_escaped .= 'data-nectar-img-src="'.esc_url($image_src).'" ';
                                                
                                                $placeholder_img_src = "data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%20".esc_attr($image_width).'%20'.esc_attr($image_height)."'%2F%3E";
                                                
                                                echo '<img class="nectar-lazy skip-lazy" '.$image_attrs_escaped.'="" src="'.$placeholder_img_src.'">';
                                            }
                                            
                                        } else {
                                            echo get_the_post_thumbnail( $post->ID, $related_image_size, array( 'title' => '' ) ); 
                                        }
                                        
                                        echo '</span>';
                                    }
                                    ?>
                                    <?php
                                    echo '<span class="meta-category">';
                                    $categories = get_the_category();
                                    if ( ! empty( $categories ) ) {
                                        $output = null;
                                        foreach ( $categories as $category ) {
                                            $output .= '<a class="' . esc_attr( $category->slug ) . '" href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
                                        }
                                        echo trim( $output );
                                    }
                                    echo ''; 
                                    ?>
                                    ><a class="entire-meta-link" href="<?php the_permalink(); ?>" aria-label="<?php echo get_the_title(); ?>"></a>
                                    <div class="article-content-wrap">
                                        <div class="post-header">
                                            <span class="meta">
                                                <?php
                                                if ( $related_post_style != 'material' ) {
                                                    echo get_the_date();
                                                }
                                                ?>
                                            </span>
                                            <p class="title"><?php the_title(); ?></p>
                                            <?php if( true === $related_post_excerpt ) {
                                                // Excerpt.
                                                $excerpt_length = ( ! empty( $nectar_options['blog_excerpt_length'] ) ) ? intval( $nectar_options['blog_excerpt_length'] ) : 15;
                                        echo '<div class="excerpt"-->';
                                        echo nectar_excerpt( $excerpt_length );
                                        echo '</div>';
                                            } ?>
                                        </div><!--/post-header-->
                                        <?php
                                        if ( function_exists( 'get_avatar' ) && $related_post_style === 'material' ) {
                                            echo '<div class="grav-wrap"-->' . get_avatar( get_the_author_meta( 'email' ), 70, null, get_the_author() ) . '<div class="text"> <a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>' . get_the_date() . '</div></div>';
                                        }
                                        ?>
                                    </div>
                                    <?php if ( $related_post_style != 'material' ) { ?>
                                        <div class="post-meta">
                                            <span class="meta-author"> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"> <i class="icon-default-style icon-salient-m-user"></i> <!--?php the_author(); ?--></a> </span>
                                            <?php if ( comments_open() ) { ?>
                                                <span class="meta-comment-count">  <a href="<?php comments_link(); ?>">
                                                    <i class="icon-default-style steadysets-icon-chat-3"></i> <?php comments_number( '0', '1', '%' ); ?></a>
                                                </span>
                                            <?php } ?>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                            <?php
                        endwhile;
                    endif;
                    echo '</div>';
                }
                else {
                    $related_title_class = apply_filters('nectar_related_posts_title_class', 'related-title');
                    echo '<div class="row vc_row-fluid full-width-section related-post-wrap post-loop-builder" data-midnight="dark">';
                    $related_title_text = nectar_get_related_post_title();
                    if ($related_title_text !== 'hidden' && $related_post_count > 1 ) {
                        echo '<h3 class="'.$related_title_class.'">' . wp_kses_post( $related_title_text ) . '</h3>';
                    }
                    do_action('nectar_before_blog_loop_content');
                    if ( $related_posts_query->have_posts() ) : while ( $related_posts_query->have_posts() ) : $related_posts_query->the_post();
                        do_action('nectar_blog_loop_post_item');
                        endwhile;
                    endif;
                    do_action('nectar_after_blog_loop_content');
                    echo '</div>';
                    
                }
                 wp_reset_postdata();
             }// if has categories
            }