Latest articles structured data markup Topic is solved

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
john1924
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Oct 09, 2012 7:18 pm
Contact:

Latest articles structured data markup

Post by john1924 » Sat Nov 16, 2019 12:26 pm

Hello, i had added microdata in every article manualy and it works fine.
Now i want to insert them to latest articles module.
I had override the module in my template and i added:

Code: Select all

<li itemscope itemtype="https://schema.org/Article">
  <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<span itemprop="name" content="...your organization name..."></span>
<span itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
                   <link itemprop="url" href="/images/KS.jpg">
                   <meta itemprop="width" content="50">
                   <meta itemprop="height" content="50">
                </span></span>
                <span itemprop="author" content="...your name..."></span>
and it works for organization, organization image - logo and author.
Next i added:

Code: Select all

<meta itemprop="datePublished" content="<?php echo JHtml::_('date', $item->publish_up, JText::_('Y-m-dTh:m:s')); ?> " > 
and it works for published date.
Now i have 3 problems. 1) I want to markup modified date. I added:

Code: Select all

<meta itemprop="dateModified" content="<?php echo JHtml::_('date', $item->modified, JText::_('Y-m-dTh:m:s')); ?> " > 
but it returns the same date as publish date or the current date.
2) i want to markup articles image. I added:

Code: Select all

<?php $images = json_decode($item->images);
?>
  <span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
  <link itemprop="url" href="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>">
  <meta itemprop="width" content="150">
                   <meta itemprop="height" content="100">
                </span>
and it works fine, but only for intro images through article image and links tab. I have my images in my html (not in image and links tab) and i want to extract image url from html. Atricles are 400+ and i prefer to extract image from html.
3) i want to markup "mainEntityOfPage". What is this?
Sorry for the long post. Thank you in advance

john1924
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Oct 09, 2012 7:18 pm
Contact:

Re: Latest articles structured data markup

Post by john1924 » Sat Nov 16, 2019 7:29 pm

No 3 (mainEntityOfPage) solved with:

Code: Select all

<link itemprop="mainEntityOfPage" href="<?php echo $item->link; ?>" /> 

john1924
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Oct 09, 2012 7:18 pm
Contact:

Re: Latest articles structured data markup

Post by john1924 » Sat Nov 16, 2019 7:45 pm

No 1 (modified date) solved with:

Code: Select all

<meta itemprop="dateModified" content="<?php echo JHtml::_('date', $item->modified, JText::_('Y-m-dTh:m:s')); ?> " >
which is the same code i tried before and it showed same date with publish. Now is working ... :-[


The only remaining issue is No 2 extract article image from html.

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1649
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Latest articles structured data markup

Post by SharkyKZ » Sun Nov 17, 2019 9:19 am

To extract images from text you can use some DOM library (reliable but slow) or regular expressions (faster, but parsing HTML is not recommended).

Basic example using DOMDocument:

Code: Select all

// Create new DOMDocument object.
$dom = new DOMDOcument;

// Load article text into DOMDocument.
$dom->loadHTML($item->introtext);

// Get all images.
$images = $dom->getElementsByTagName('img');

// If article contains an image, get its URL.
$imageSrc = $images[0] ? $images[0]->getAttribute('src') : null;

// Output the image.
if ($imageSrc !== null)
{
	echo '<img src="' . $imageSrc . '">';
}

john1924
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Oct 09, 2012 7:18 pm
Contact:

Re: Latest articles structured data markup

Post by john1924 » Sun Nov 17, 2019 10:37 am

Thank you @SharkyKZ.
I changed

Code: Select all

echo '<img src="' . $imageSrc . '">';
with

Code: Select all

echo '' . $imageSrc . '>';
to match href and it worked.

I also use it for alt, changing

Code: Select all

$imageSrc = $images[0] ? $images[0]->getAttribute('scr') : null;
with

Code: Select all

$imageSrc = $images[0] ? $images[0]->getAttribute('alt') : null;
Thank you very much

john1924
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Oct 09, 2012 7:18 pm
Contact:

Re: Latest articles structured data markup

Post by john1924 » Sun Nov 17, 2019 10:39 am

how can i mark my question as solved?


Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”