PDA

View Full Version : Showing Author Avatar in Articles


SilverBoy
04-11-2013, 03:37 PM
Hi all

I used this nice plugin to show author avatar in the articles.
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/vbulletin-4-quick-tips-and-customizations/396751-how-to-add-user-avatar-to-cms-articles

The problem is, I don't want to show avatars in all articles, but only on opinion articles and reviews, but for news articles no avatars at all.

I thought in this problem, and then added a custom field to the articles to show or not show user avatars, I followed this nice article (guide)
https://vborg.vbsupport.ru/showthread.php?t=257589
Actually I did the first 4 points, and it seems work great (changing and saving every time), but I don't complete the steps.

What I want know, is how I can use my new field to control the plugin that shows avatars?

let we say the new field named showavatar.

Sorry but I'm very new in coding vb4 and vbcms

Thanks in advance

Lynne
04-11-2013, 04:40 PM
If the new field is called showavatar, then grab the variable at the beting of your show author avatar plugin and then use it in a condition:

if ($showavatar) {
code here to show avatar
}

SilverBoy
04-12-2013, 03:21 PM
Thank you for your appreciate help.

How I can grab the variable Lynne?

Lynne
04-12-2013, 04:23 PM
You didn't really say where you added it, so I don't really know. You probably have to do a query unless the variable is already there. I really can't tell since you have posted no code or anything.

SilverBoy
04-12-2013, 06:57 PM
Thank you Lynne for your reply.

I want to display the avatars in both article page and section page (article preview).
By technical words I want to display avatar in "vbcms_content_article_page" and "vbcms_content_article_preview" templates, and now without the condition the avatars shows very well, but as I said before I don't want to show avatars for all articles.

Here is the code that reefland added in vb.com
require_once(DIR . '/includes/functions_user.php');

$avatarurl = fetch_avatar_url($this->content->getUserId());
if ($avatarurl[0]) {
$avatarurl = $avatarurl[0];
}
/* render template and register variables */
vB_Template::preRegister('vbcms_content_article_pa ge',array('avatarurl' => $avatarurl));

I just added this line to it to let avatars appear also in section page
vB_Template::preRegister('vbcms_content_article_pr eview',array('avatarurl' => $avatarurl));

Any suggestions?

BTW, regarding to this article, https://vborg.vbsupport.ru/showthread.php?t=257589
I try to complete the steps to show another field in articles, but I get error 500 when adding the plugin in step 9 !!

Waiting for your help Lynne :), and thanks in advance.

Lynne
04-12-2013, 08:52 PM
And what hook location did you use for the $avatarurl code? Perhaps that hook isn't used on the section page. Also, you can't just preregister the variable, you also need to actually add that variable to the template you preregistered it for use in.

SilverBoy
04-12-2013, 09:15 PM
I put the code in the hook as this thread says
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/vbulletin-4-quick-tips-and-customizations/396751-how-to-add-user-avatar-to-cms-articles
"vbcms_article_populate_end".

As I told you, now without conditions the avatars appears in both pages (article page and section page).

--------------- Added 1365811144 at 1365811144 ---------------

Is there any suggestion? :)

Lynne
04-12-2013, 11:51 PM
You said:
What I want know, is how I can use my new field to control the plugin that shows avatars?
So, what is this new field - what is it called and where is it in the database (table.field)? And have you done anything in the plugin to make sure it is available for you to use?

SilverBoy
04-13-2013, 12:13 AM
The new field as I told you in the previous post named "showavatar", and it added to cms_node table.

I did every thing in this plugin
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/vbulletin-4-quick-tips-and-customizations/396751-how-to-add-user-avatar-to-cms-articles
and it is work as charm, but I want now to use my showavatar field to show/hide avatars.

--------------- Added 1365815805 at 1365815805 ---------------

As I told you, I'm new with vb4 and vbcms, I'm just coming from days of vb3, so every thing is new for me and I'm confused a little bit, I want to use my field value (1 or 0) to control the whole process, but I want to declare the showavatar in the plugin before I can use it in the condition, but I don't know how I can do this :).

--------------- Added 1365815898 at 1365815898 ---------------

The plugin now without the condition works great, just to clear the picture ;).

Lynne
04-13-2013, 03:04 AM
If you added it to that table, did you also modify the query that grabs fields from that table to make sure to grab that field?

SilverBoy
04-13-2013, 03:33 AM
No, where I can find it?

Lynne
04-13-2013, 03:43 PM
Well, um.... you added it, didn't you? So, you must know exactly where you added it.

SilverBoy
04-13-2013, 05:42 PM
Lynne !!

I told you, I did what the article of Yellow Slider said nothing more !!
I added the field manually using phpmyadmin, and I told you I don't know where the vbcms called the variables from that table, so if you can help me or another guy you will be very thankful.

--------------- Added 1365878807 at 1365878807 ---------------

I know where I added the field "showavatar" to the table "cms_node", I think I gave this information before, so please help me to find a way to call my variable to use it in my plugin.

Any help?

--------------- Added 1365915495 at 1365915495 ---------------

No suggestions???

Please ignoring what I did, just start from this plugin
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/vbulletin-4-quick-tips-and-customizations/396751-how-to-add-user-avatar-to-cms-articles

And then give me a way to control when I can show the avatar and when I made it off !!

--------------- Added 1365920735 at 1365920735 ---------------

Finally I figured it out by myself :).
The problem was in Yellow Slider article there is any mention to add your field to the select query, so there is nothing appear in the page, now I can control avatars to show or hide in the page and show any other fields in the article page too :).