Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
836 views
in Q2A Core by

Hi,

Could anyone suggest a hack to add the users website (taken from their profile page) to display on the question page when they submit an answer?

Will this have a noticably detrimental impact on performance?

Essentially what I'm trying to do is reward those people giving answers by encouraging users to visit their website (image mockup below).

Thanks!

 

Q2A version: 1.6.3

1 Answer

+3 votes
by
selected by
 
Best answer

This questions is quite related to this one: http://www.question2answer.org/qa/37836/how-can-i-display-users-full-name

The answer is essantially the same. Open the qa-include/qa-app-format.php file and try this code. Green lines are the new added ones:

if (isset($postuserid) && isset($usershtml[$postuserid])) {
    $whohtml=$usershtml[$postuserid];
    if ($microformats)
        $whohtml='<span class="vcard author">'.$whohtml.'</span>';
    $userprofile = qa_db_select_with_pending(qa_db_user_profile_selectspec($postuserid, true));
    if (isset($userprofile['website']) && !empty($userprofile['website'])) {
        $whohtml .= ' Website: ' . qa_html($userprofile['website']);
    }
} else {
 
Of course, you can add a link instead of just the text but in your case you just seem to want the text.
 
Regarding performance, the explanation is simple: this will run a quick query each time the information is requested (the query is needed even if the user has not set a website in their profile). This means if you have a question list with 20 questions then this query will be run 20 times.
 
As I mentioned in the other question, this can be improved with a plugin so that it runs only one time per question list. However, that's more complex and not actually suitable for an answer but rather a tutorial targeted to users that know about PHP.
 
Conclusion, give it a try. I bet you won't notice anything... unless you have around 100 users browsing a question list page at the same time :)
by
Seems to work fine (thanks!). Just one Tweak if possible? I'd like the website to be hyperlinked and nofollowed?
by
Then instead of this line:

$whohtml .= ' Website: ' . qa_html($userprofile['website']);

Use this one:

$whohtml .= ' Website: ' . qa_url_to_html_link($userprofile['website'], true);

The "true" up there determines if the link should be opened in a new window or not. It can be "false".

PS: As I always say, no need of saying thanks, that's what upvoting/accepting answers is there for :)
by
Brilliant. Thanks!
...