This object is in archive! 

Adding Open Graph to Responses

Archived Annevar Media, LLC 9 years ago

Okay so this is a two parter, first is a feature suggestion, second is a question on how to write these variables. So I decided to put it under Idea, please change it to Question if you think it necessary.

I am creating Open Graph meta tags for the different templates in UR. Right now I am working on response.phtml. I have not gotten very far digging through the source code. Here is where I am:

  1. <meta property="og:site_name" content=""/>
  2. <meta property="og:title" content="" />
  3. <meta property="og:url" content=""/>
  4. <meta property="og:type" content="article"/>
  5. <meta property="og:description" content="" />
  6. <meta property="og:image" content="<?php echo ($this->settings->system->general->site_logo->value) ? $this->baseUrl('/public/files/logo/' . $this->settings->system->general->site_logo->value) : $this->imageSrc('branding/logo.png', null, false) ?>" />
  7. <meta property="article:published_time" content="2014-10-10">
  8. <meta property="article:section" content="">
  9. <?php foreach($this->activeResponse->getTags() as $tag):?>
  10. <meta property="article:tag" content="<?php echo $this->escape($tag)?>">
  11. <?php endforeach?>

What I need help with is how do I echo the Community Title, Response Title, Response URL, Response Description, Date Created (not relative, but YYYY-MM-DD), and Category (primary, or first)

This will also allow me to write the meta tags for main.phtml:

  1. <meta property="og:site_name" content=""/>
  2. <meta property="og:type" content="website"/>
  3. <meta property="og:image" content="<?php echo ($this->settings->system->general->site_logo->value) ? $this->baseUrl('/public/files/logo/' . $this->settings->system->general->site_logo->value) : $this->imageSrc('branding/logo.png', null, false) ?>" />

And for profile.phtml:

  1. <meta property="og:site_name" content=""/>
  2. <meta property="og:type" content="profile">
  3. <meta property="og:title" content="<?php echo $this->activeResponse->getAuthor() ?>" />
  4. <meta property="og:url" content="<?php echo $this->url(array('user_id' => $this->activeUser->id), 'profile')?>" />
  5. <meta property="og:image" content="<?php echo ($this->settings->system->general->site_logo->value) ? $this->baseUrl('/public/files/logo/' . $this->settings->system->general->site_logo->value) : $this->imageSrc('branding/logo.png', null, false) ?>" />

Thanks!

Ken

Replies (3)

photo
1

Hello, Ken.


As I understand you need to get response creation datetime in MySQL format.

So, this is solution:

  1. $this->activeResponse->created_at

If you need to get response categories use the following snippet:

  1. $categoriesModel = new Categories_Model_DbTable_Categories();
  2. $responseCategories = $categoriesMode->findByResponseId(
  3. $this->activeResponse->id
  4. );
  5. if ($responseCategories->valid()) {
  6. foreach ($responseCategories as $category) {
  7. /* your implementation here... */
  8. }
  9. }

photo
1

Okay, great start! Can you please tell me how to render these variables to the screen?


Community Title, Response Title, Response URL, Response Description


Thank you!

photo
1

The following code should be used inside controller action:

  1. /* Community Title */
  2. Singular_Core::_('Settings')->getSetting('site_title');
  3. /* Response Title */
  4. $this->activeResponse->title;
  5. /* Response URL*/
  6. $this->activeResponse->getUrl();
  7. /* Response Content*/
  8. $this->view->bbcode($this->activeResponse->content, true, $this->activeResponse);

You can pass data to template by using $this->view->yourVar = 'yourVal';

Replies have been locked on this page!