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

ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
eange08
PHP VIP Members
PHP VIP Members
โพสต์: 16018
ลงทะเบียนเมื่อ: 22/12/2020 10:09 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย eange08 »

ทำ 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');
?>
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41127
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ใส่เป็น tag script ของ json ลงไปในหน้าที่ต้องการเลยครับ
id ของบทความ หรือ เนื้อหามันจะดึงข้อมูลที่แตกต่างกัน
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 46