0

There is the following code that works correctly, that is, the title of the post is displayed and after the comma its category name on the page in the header:

 <?php foreach (HTML_SOBI::getMyCategories($mySobi) as $category) { echo $category['name'];}?></h1> 

How can I display a post with the same title, category ['name'] format in OpenGraph?

The following working code but no category name:

<meta property="og:title" content="'.$mySobi->title.'" />

How can I correctly add the category name after the title, separated by commas? This part of code: <?php foreach (HTML_SOBI::getMyCategories($mySobi) as $category) { echo $category['name'];}?>

Igor
  • 1
  • 1
  • If you are doing Joomla development, please join [joomla.se] Stack Exchange and ask your Joomla-related questions there. – mickmackusa Jun 19 '21 at 23:30

2 Answers2

0

Just try this

 echo $mySobi->title.' , '.$category;

Apply it like this

$YouTitle = "MY TITLE";
$category = "MY CATEGORY";
$Meta = $YouTitle." , ".$category;

echo'<meta property="og:title" content="'.$Meta.'" />';

Or from an array

$source = array(
    "Title" => "My Title",
    "category" => "My Category"
    );

$meta = $source['Title']." , ".$source['category'];

echo'<meta property="og:title" content="'.$meta.'" />';
il4mb
  • 105
  • 1
  • 5
  • The following working code but no category name: `` where to insert your solution? – Igor Jun 15 '21 at 20:59
  • How can I understand if I don't know where your category is from and what source your title is from?, you have to enter a script of where the category comes from – il4mb Jun 15 '21 at 22:44
  • `Apply it like this` works super! however, how to call the category name? `$category = "MY CATEGORY"; ` `$category = ""; ` ?? – Igor Jun 16 '21 at 07:33
0

If I understood the question properly, this might be what you want:

$categories = array_map(function($category) {
    return $category['name'];
}, HTML_SOBI::getMyCategories($mySobi));
$opengraph_meta=' <meta property="og:title" content="'.$mySobi->title.' '.implode(', ', $categories).'" />';
shaedrich
  • 5,457
  • 3
  • 26
  • 42