Announcement

Collapse
No announcement yet.

How-To: Add User Avatar to CMS Articles

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How-To: Add User Avatar to CMS Articles

    Maybe a mod will move this to the Tips and Tricks forum...

    The vBCMS provides a user with the functionality to customize their site to meet their needs. I understand most users would prefer to have out of the box solutions to their needs but sometimes this is not always available. Luckily for us, we have the tools necessary to do the additions we want. As I go through customizing my site, I thought I would share some of the items I have done.

    Add the authors avatar to the article page


    1. Create a plugin:
    Product - vBulletin CMS
    Hook Location - vbcms_article_populate_end (vBulletin CMS)
    Title - Whatever you like
    Execution Order - 1
    Plugin Code:
    PHP Code:
    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_page',array('avatarurl' => $avatarurl)); 
    2. In the style you want to add the avatar to, edit template vbcms_content_article_page and add where you want the avatar to show:
    Code:
    <img src="{vb:raw avatarurl}" alt="Author Avatar" />
    Important: Use my code at your own risk. I take no responsibility for any problems or data loss this may cause.
    Last edited by reefland; Sun 1st Jan '12, 7:13pm.
    sigpic
    Nation of Blue - Kentucky Wildcats Sports


    Some CMS Goodness: Add Avatar to Article

  • #2
    Perhaps I'm just being pedantic, but the author's id is already in scope, so your code should be able to be reduced to:

    PHP Code:
    require_once('includes/functions_user.php');
    $avatarurl fetch_avatar_url($view->authoridtrue);
    $view->avatarurl $avatarurl[0] ? $avatarurl[0] : $avatarurl
    Also, unless you're also adding the avatar to the preview, you'll want to wrap it around conditional tags...otherwise, it'll also be run when generating the preview:

    PHP Code:
    if(self::VIEW_PAGE == $viewtype)
    {
    require_once(
    'includes/functions_user.php');
    $avatarurl fetch_avatar_url($view->authoridtrue);
    $view->avatarurl $avatarurl[0] ? $avatarurl[0] : $avatarurl;

    (completely untested, and I'm trusting you know what you're doing with the fetch_avatar_url function. )

    Comment


    • #3
      Thanks for the pointers! Your code didn't completely work for me but the authorid did allow me to get rid of the query!

      PHP Code:
      require_once(DIR '/includes/functions_user.php');
      if(
      $nodeid != '') {
      $avatarurl fetch_avatar_url($view->authoridtrue);if ($avatarurl[0]) {
      $avatarurl $avatarurl[0];
      }
      /* render template and register variables */vB_Template::preRegister('vbcms_content_article_page',array('avatarurl' => $avatarurl));

      sigpic
      Nation of Blue - Kentucky Wildcats Sports


      Some CMS Goodness: Add Avatar to Article

      Comment

      Related Topics

      Collapse

      Working...
      X