Change to Review/comment Header

This topic contains 6 replies, has 3 voices, and was last updated by  Kiran 4 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #497689

    Neil Hall
    Buyer
    Post count: 83

    Hi

    I would like to make some changes to the the Review header, for example
    1. add url link to avatar
    2. Add a line stating which language the review was written in
    3. Add date when place was visited
    4. Add date when the review was written

    In Geodirectory V1 I achieved this by editing the comments_functions.php file which I suppose I could also do in Version 2
    But is there a better way of achieving this?

    Best Regards
    Neil

    #497691

    Alex Rollin
    Moderator
    Post count: 27815

    Let me flag your topic for the developers so they can advise you about that.

    #497932

    Kiran
    Moderator
    Post count: 7069

    Hello Neil,

    1. add url link to avatar

    Avatar is rendered via WordPress function. Which link url you want to add to avatar?

    2. Add a line stating which language the review was written in

    Not possible without code customization.

    3. Add date when place was visited

    Clarify with more details where you want to add date.

    4. Add date when the review was written

    Try following snippet to display date.

    
    
    /**
     * Show review date.
     */
    function gd_snippet_190716_review_time() {
    	?>
    <script type="text/javascript">/* <![CDATA[ */
        jQuery(function($){
    		$('span.geodir-review-time').each(function(){
    			$title = $(this).prop('title');
    			$date = $(this).text();
    			if ($title && $date) {
    				$(this).prop('title', $date);
    				$(this).text($title);
    			}
    		});
    	});
    /* ]]> */</script>
    	<?php
    }
    add_action( 'wp_head', 'gd_snippet_190716_review_time' );

    In Geodirectory V1 I achieved this by editing the comments_functions.php file which I suppose I could also do in Version 2
    But is there a better way of achieving this?

    You can achieve by doing customization with the use of hooks but don’t modify any core file, otherwise it will break functionality.

    Regards,
    Kiran

    #498129

    Neil Hall
    Buyer
    Post count: 83

    Hi Kiran

    Thanks for coming back to me. In answer to your questions:
    1. add url link to avatar
    I guess I would need to change geodirectory/includes/class-geodir-comments.php line 533

    
    $avatar_size = apply_filters( 'geodir_comment_avatar_size', 44 );
    echo get_avatar( $comment, $avatar_size );
    printf( '<cite><b class="reviewer">%1$s</b> %2$s</cite>',
    

    To

    
    $avatar_size = apply_filters('geodir_comment_avatar_size', 44);
    $user_profile_url = get_author_posts_url( $comment->user_id );
    $comment_user_id = $comment->user_id;
    echo '';
    echo get_avatar($comment, $avatar_size);
    echo '';
    printf('<cite><b class="reviewer">%1$s</b> %2$s</cite>',
    

    2. Add a line stating which language the review was written in.
    In V1 I had the following code in my functions.php but I’m not sure how to get it to work in V2

    
    /*
    ==========================================================
    Adding Language written to Profile Tabs in Detail Listing
    ==========================================================
    */
    add_action('geodir_before_tab_content','my_text_before_profile' ,10,1 );
    
    function my_text_before_profile($tab_index ){
    $country = get_post_meta(get_the_ID(),'tp_language',true);
    $countryList = array(
    	'de' => 'German',
    	'en' => 'English',
    	'es' => 'Spanish',
    	'fr' => 'French',
    	'it' => 'Italian',
    	'nl' => 'Dutch');
    	$language = $countryList[$country];
    if($tab_index=='post_profile'){
    echo "<h6>This text was written in $language";
    echo ' - For the original text ';
    echo '<span class="no_translate">';
    echo '<a href="';
    echo site_url();
    echo "/$country";
    echo str_replace(home_url(), '', get_permalink());
    echo ' "> ';
    echo '</span>';
    echo 'click here</h6>';
    echo '';
    }
    }
    

    3. Add date when place was visited
    I guess that something like this would need to be inserted in geodirectory/includes/class-geodir-comments.phpbefore line 558 – <section class=”comment-content comment”>

    
    echo "<span class='item'>";
    $key = 'date_visited';
    $themeta = get_comment_meta(get_comment_ID(), $key, TRUE);
    if($themeta != '') {
    echo 'Visited ';
    }
    echo "$post->post_title";
    $key = 'date_visited';
    $themeta = get_comment_meta(get_comment_ID(), $key, TRUE);
    if($themeta != '') {
    echo ' on ';
    echo $display_date = date('d F, Y', strtotime(get_comment_meta( get_comment_ID(), 'date_visited', true)));
     }
    echo "</span>";
    $country = get_comment_meta(get_comment_ID(), 'tp_language', TRUE);
    if($country != '') {
    $countryList = array(
    	'nl' => 'Dutch',
    	'en' => 'English',
    	'es' => 'Spanish',
    	'fr' => 'French',
    	'it' => 'Italian',
    	'de' => 'German');
    	$language = $countryList[$country];
    echo "<span class='item'>";
    echo "This Review was written in $language";
    echo ' - For the original text ';
    echo '<span class="no_translate">';
    echo '<a href="';
    echo site_url();
    echo "/$country";
    echo str_replace(home_url(), '', get_comment_link($comment->comment_ID));
    echo ' "> ';
    echo '</span>';
    echo 'click here';
    echo '';
    echo "</span>";
    }
    

    4. Add date when the review was written
    geodirectory/includes/class-geodir-comments.php line 544

    
    printf( '<span class="geodir-review-time" title="%3$s">%2$s</span>',
    esc_url( get_comment_link( $comment->comment_ID ) ),
    sprintf( _x( '%s ago', '%s = human-readable time difference', 'geodirectory' ), human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) ),
    sprintf( __( '%1$s at %2$s', 'geodirectory' ), get_comment_date(), get_comment_time() )
    );
    

    To

    
    printf( '<span class="geodir-review-time" title="%3$s">%2$s</span>',
    esc_url( get_comment_link( $comment->comment_ID ) ),
    sprintf( _x( '%s ago', '%s = human-readable time difference', 'geodirectory' ), human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) ),
    sprintf( __( 'This Review was posted on %1$s at %2$s', 'geodirectory' ), get_comment_date(), get_comment_time() )
    );
    

    At present my site shows the date as the human readable time difference. How can I get it just to show the Date and Time posted?

    I do not understand how to do ‘customization with the use of hooks’. Any help would be appreciated.

    Best Regards
    Neil

    #498606

    Kiran
    Moderator
    Post count: 7069

    1. add url link to avatar

    Try following PHP code snippet.

    
    
    /**
     * Add author link to review author avatar.
     */
    function gd_snippet_190719_get_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {
    	if ( ! empty( $id_or_email ) && is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) && ! empty( $id_or_email->comment_post_ID ) && geodir_is_gd_post_type( get_post_type( $id_or_email->comment_post_ID ) ) ) {
    		$avatar = '<a class="_gd-review-author" href="' . esc_url( get_author_posts_url( $id_or_email->user_id ) ) . '">' . $avatar . '</a>';		
    	}
    	return $avatar;
    }
    add_filter( 'get_avatar', 'gd_snippet_190719_get_avatar', 10, 6 );

    At present my site shows the date as the human readable time difference. How can I get it just to show the Date and Time posted?

    Did you tried snippet i provided in my previous reply?

    I do not understand how to do ‘customization with the use of hooks’. Any help would be appreciated.

    We don’t provide support for customization. Yes, we sometimes provide snippet for easy customization. You can hire developer for more customization from here: https://geodirectoryexperts.com/

    Kiran

    #499079

    Neil Hall
    Buyer
    Post count: 83

    Hi Kiran

    Many thanks for your help. The code for 1. add url link to avatar works perfectly.

    For the 4. Add date when the review was written the code also works and the actual date is now showing. Is there a way of adding some text in front of the date? For example ‘This review was written on’

    Best Regards
    Neil

    #499119

    Kiran
    Moderator
    Post count: 7069

    Hello,

    To add text ‘This review was written on’ before date, just replace

    $(this).text($title);

    to

    $(this).text('This review was written on ' + $title);

    Kiran

Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket