ทำ google structured ใช้แบบ Json แล้วหน้าที่แสดงบทความเดียวกันหมด

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ทำ google structured ใช้แบบ Json แล้วหน้าที่แสดงบทความเดียวกันหมด

Re: ทำ google structured ใช้แบบ Json แล้วหน้าที่แสดงบทความเดียวกันหมด

โดย mindphp » 02/03/2021 6:45 pm

ใส่เป็น tag script ของ json ลงไปในหน้าที่ต้องการเลยครับ
id ของบทความ หรือ เนื้อหามันจะดึงข้อมูลที่แตกต่างกัน

ทำ google structured ใช้แบบ Json แล้วหน้าที่แสดงบทความเดียวกันหมด

โดย eange08 » 02/03/2021 6:38 pm

ทำ google structured เปลี่ยนมาเป็นแบบ Json พอเข้าไปที่บทความแต่ละอัน ขึ้นเป็นบทความนี้เดียวกันหมด
ต้องแก้ไขอย่างไรค่ะ
screenshot-localhost-2021.03.02-18_37_37.png
Code ทำ google structured

โค้ด: เลือกทั้งหมด

<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');

$doc = JFactory::getDocument();
$doc->addScript(JUri::root() . 'templates/***/js/prism.js');
$doc->addStyleSheet(JUri::root() . 'templates/***/css/prism.css');

// Create shortcuts to some parameters.
$params  = $this->item->params;
$images  = json_decode($this->item->images);
$urls    = json_decode($this->item->urls);
$canEdit = $params->get('access-edit');
$user    = JFactory::getUser();
$info    = $params->get('info_block_position', 0);
JHtml::_('behavior.caption');
$image_default = 'images/logo.png'; 

$name_type_article = '';
$url_type_article = '';
if ($params->get('show_title') == 1 || $params->get('show_author') ==1) :   
         $name_type_article = $this->escape($this->item->title);
         $url_type_article = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->id, $this->item->catid, $this->item->language));
endif;

$google_structured=array(
   "@context" => "http://schema.org",
  "@type"=> "Article",
  "name"=> $name_type_article,
  "url"=> $url_type_article,
 
);

$doc->addScriptDeclaration( json_encode($google_structured), 'application/ld+json');
?>

ข้างบน