Posts Tagged wordpress

Showing custom comments saved values to visitors

Hi everyone
It’s been a long time since I wrote something
Due to requests for showing the custom fields in the template I searched a little bit and finally found the easiest solution
So what should you do?

First of all
Go to you template directory (in default template it’s “wp-content/themes/twentyten”)
Second
Open comments.php and search for “wp_list_comments”(Don’t search with quotes :P)
Third
Do you see the “something” in wp_list_comments( array( ‘callback’ => ‘something’ ) );?
That’s the function that will be overwrite the default template for comments
If it’s not there add it and instead of something write the name you like
Fourth
Now open functions.php
If you haven’t changed anything in comments.php so search for “something”(the name of the function)
Now you you should add this code to this function wherever you want(put it in different place to see where it will appear-at the beginning it will be before author and at the end after the reply link-)

The function


$CComment_fields = array_filter(explode(",", get_option('CComment_fields')));
foreach ($CComment_fields as $CComment_field){
$CComment_field_arr = explode(";CuCo;", get_option($CComment_field));
$CComment_field_desc = $CComment_field_arr[0];
$CComment_field_active = $CComment_field_arr[1];
$Comment_field_value = get_comment_meta(get_comment_ID(), "CuCo_".$CComment_field);
if ($CComment_field_active == 1)
echo $CComment_field_desc.' : '. (($Comment_field_value[0] != '') ? $Comment_field_value[0] : '-');
}

Do you see this line “echo $CComment_field_desc.’ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);”?
It’s the part that prints each of custom field and it’s value
Just play with it as you please(add class, id or whatever you want)
For example
echo ‘
<div class=”cc-field”>’ . $CComment_field_desc .</div>
. ‘ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);
I hope this helps
Thanks for all of the comments about this plugin 🙂

Advertisements

, , ,

3 Comments

custom comment future updates

Well when I fixed all of the bugs in this plugin I thought that now there is nothing left to do with this plugin
But when I walked out of the office I thought it would be good to add some more options
So let me explain to you what the future options be(As soon as I find some free time :D)
1- type of the extra field(number, string(min, max length), combo box, check box)
2- string validation(with regular expression)
3- show the extra fields in the post or not
4- send the extra fields to the email(along with the main fields)

These are what I thought until now
If you have anymore suggestion please tell me and I will add it here and of course I will mention your name in the code(with a link);)
This post will be a future reference for me to remember what I wanted to do with this plugin
p.s: If you make any improvement for the plugin send it to me in order not to lose the improvements when I update the plugin to a newer version
Wish me free time:P

, , , , ,

2 Comments