schema.org Category view: 5 errors for each item/article (only 1 in item view)

More
6 years 2 months ago - 6 years 2 months ago #77645 by iamrobert
I do it via json in item.php and avoid itemscope:
Code:
<?php /* + STRUCTURED DATA GOOGLE ======================================================================*/ $structured_data = ''; ?> <?php if ($show_schema == 1) : ?> <?php if (($microdata_itemtype == 'Article')||($microdata_itemtype == 'NewsArticle')||($microdata_itemtype == 'BlogPosting')): ?> <?php if ( $json_description != '' || $imageURL != '' ) { $structured_data .= '<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "' . $microdata_itemtype . '", "mainEntityOfPage": { "@type": "WebPage", "@id": "' . JURI::current() . '" }, "headline": ' . json_encode( $item->title, JSON_UNESCAPED_UNICODE ) . ', ' . $JSONimageURL . ' ' . $datePublished . ' ' . $dateModified . ' "author": { "@type": "Person", "name": ' . json_encode( $author, JSON_UNESCAPED_UNICODE ) . ' }, "publisher": { "@type": "Organization", "name": ' . json_encode( $company_brand_name, JSON_UNESCAPED_UNICODE ) . ', "logo": { "@type": "ImageObject", "url": "' . $company_logo_image_name . '" } }, "description": ' . json_encode( $json_description, JSON_UNESCAPED_UNICODE ) . ' } </script>'; } ?> <?php endif; ?> <?php endif; ?>

To call the values I have a lobal-logic.php file called in item.php:
require_once( JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'templates' . DS . 'iamrobert' . DS . 'common-code' . DS . 'global-logic.php' );


global-logic.php
Code:
<?php defined( '_JEXEC' )or die( 'Restricted access' ); /* + OPEN GRAPH META TAGSSOCIAL SHARES https://blog.kissmetrics.com/open-graph-meta-tags/ https://moz.com/blog/meta-data-templates-123 ----------------------------------------------------------------------- REMEMBER TO SET IMAGE FIELD NUMBER line 81 ====================================================================== */ $document = JFactory::getDocument(); $app = JFactory::getApplication(); //TEMPLATE PATH $tpath = JURI::base(true).'/templates/'.$app->getTemplate().'/'; //$app = JFactory::getApplication('site'); $template = $app->getTemplate(true); /* + COMPANY NAME + LOGO = Set in Joomla Site Template ======================================================================*/ // $company_brand_name = $template->params->get('company_brand_name'); $company_logo_image_name = JURI::base() . $template->params->get('company_logo_image_name'); if (isset($company_brand_name )) { if ($company_brand_name != 'NAME') { $company_brand_name = $template->params->get('company_brand_name'); } else if ($company_brand_name == 'NAME') { $company_brand_name = JFactory::getConfig()->get( 'sitename' ); } } //SITENAME $document->setMetaData( 'og:site_name', "$company_brand_name", 'property' ); //AUTHOR $author = $this->item->author; $datePublished = ""; //PUBLISHED DATE if(!empty ($this->item->created)) { $datePublished = date('Y-m-d',strtotime($this->item->created)); $datePublished = '"datePublished: "'.$datePublished.'",'; } $dateModified = ""; //MODIFIED DATE if(!empty ($this->item->modified)) { $dateModified = date('Y-m-d',strtotime($this->item->modified)); $dateModified = '"dateModified: "'.$dateModified.'",'; } //SITE URL: $siteURL = 'http' . ( empty( $_SERVER[ 'HTTPS' ] ) ? '' : 's' ) . '://' . $_SERVER[ 'SERVER_NAME' ]; // GET OPENGRAPH TYPE: //https://developers.facebook.com/docs/reference/opengraph/ $fb_og_type = $this->params->get( 'fb_og_type' ); //GET TITLE $page_title = $document->getTitle(); //GET CURRENT PAGE URL; $current_page_url = JURI::current(); //$document->setMetaData( 'og:site_name', "$company_name", 'property' ); //SET URL $document->setMetaData( 'og:url', "$current_page_url", 'property' ); $document->setMetaData( 'og:type', "$fb_og_type", 'property' ); $document->setMetaData( 'twitter:card', "summary_large_image" ); //SET TITLE $document->setMetaData( 'og:title', "$page_title", 'property' ); $document->setMetaData( 'twitter:title', "$page_title" ); /* + SET DESCRIPTION ======================================================================*/ //SET INTROTEXT LENGTH $intro_text_cut_text = $this->params->get( 'intro_text_cut_text', '160' ); $intro_text = JHtmlString::truncate( $item->introtext, $intro_text_cut_text, true, false ); $intro_text = str_replace( '...', '', $intro_text ); //GET META DESCRIPTION: $meta_description = $document->getMetaData( "description" ); $json_description = ''; if (!empty($_mp=$menu->params->get('menu-meta_description'))) { //+ GET MENU META DESCRIPTION $document->setDescription( $_mp ); $document->setMetaData( 'twitter:description', "$_mp" ); $document->setMetaData( 'og:description', "$_mp", 'property' ); $document->setMetaData( 'description', "$_mp", 'itemprop' ); // $json_description = $_mp; } elseif ( !empty( $item->metadesc ) ) { //+ GET ITEM META DESCRIPTION $meta_item = htmlspecialchars_decode($item->metadesc); $document->setDescription( $meta_item ); $document->setMetaData( 'twitter:description', "$meta_item" ); $document->setMetaData( 'og:description', "$meta_item", 'property' ); $document->setMetaData( 'description', "$meta_item", 'itemprop' ); $json_description = $meta_item; } elseif ( !empty( $intro_text ) ) { //+ GET INTRO TEXT META DESCRIPTION $document->setDescription("$intro_text"); $document->setMetaData( 'twitter:description', "$intro_text" ); $document->setMetaData( 'og:description', "$intro_text", 'property' ); $document->setMetaData( 'description', "$intro_text", 'itemprop' ); $json_description = $intro_text; } elseif ( !empty( $meta_description ) ) { //+ GET SIDE META DESCRIPTION $document->setDescription("$meta_description"); $document->setMetaData( 'twitter:description', "$meta_description" ); $document->setMetaData( 'og:description', "$meta_description", 'property' ); $document->setMetaData( 'description', "$meta_description", 'itemprop' ); $json_description = $meta_description; } /* + SET IMAGE FIELD NUMBER ======================================================================*/ $imagefield = 40; $imageURL = ''; $JSONimageURL = ''; if ( isset( $item->fieldvalues[ $imagefield ] ) ) { if(isset($this->item->fieldvalues[$this->item->fields['image']->id])) { $imageURL = $siteURL . $item->fields[ 'image' ]->{"display_large_src"}; $document->setMetaData( 'twitter:image', "$imageURL" ); $document->setMetaData( 'og:image', "$imageURL", 'property'); $JSONimageURL = '"image": ["'.$imageURL.'"],'; } } ?>
Last edit: 6 years 2 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
2 months 23 hours ago #86284 by flodariege
Hello,

I am a zero in coding, so could you please answer these few questions?

You write :

To call the values I have a lobal-logic.php file called in item.php:
require_once( JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'templates' . DS . 'iamrobert' . DS . 'common-code' . DS . 'global-logic.php' );

Where in item.php am I suppose to insert this line?
Anywhere? Before the code generating the JSON microdata? After ?

To adapt this line to my case, given my item php is located here :
/components/com_flexicontent/templates/default-h1/item.php

Am I supposed to place global-logic.php in this very same folder?
So the code has to be :
Code:
require_once( JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'templates' . DS . 'default-h1' . DS . 'global-logic.php' );
Is this correct?

And finally: your code is 6 years old (and still useful !!).
Do you see anything I should change in order to make it work with current versions of Flexicontent and Joomla?

Thank you very much for your help.

Dare to dream, believe the unbelievable, never take no for an answer

Please Log in or Create an account to join the conversation.

More
2 months 20 hours ago - 2 months 20 hours ago #86285 by iamrobert
I'm still in Joomla 4 at the moment but am upgrading to J5 in the coming month.

Here’s a recent build of  global-logic.php - it also includes an item.php of how I insert the code.


You can place the file in any folder you like, and you can include it in your FLEXIContent template using modern Joomla 4/5 syntax:
Code:
require_once JPATH_SITE . '/components/com_flexicontent/templates/iamrobert/common-code/item-header-logic.php';

The old . DS .  syntax is no longer needed.

I keep my own reusable code blocks in a folder called iamrobert under:

/components/com_flexicontent/templates/

This folder is not an actual FLEXIContent template - it’s simply a clean way to store reusable logic across multiple client projects.

If you're interested in the theory behind this setup, see here:  github.com/Lyquix/flexicontent_templates

Below is an example of how I structure my reusable blocks
   

Where in item.php should I insert the require_once line?

You can place it anywhere before you use the variables or functions from global-logic.php.
I put it near the top of item.php, just after the opening PHP tag.



Do I need to put global-logic.php inside the same template folder?
Not necessarily — you can put it anywhere.
You only need to adjust the path in  require_once  so Joomla knows where to find it.
 
Last edit: 2 months 20 hours ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
1 month 2 weeks ago #86290 by micker
Sorry not sure to understand all thing but it can be bettre to create your own post ?

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save