-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@id on BreadcrumbList #59
Comments
Following schema.org itself this is done by https://schema.org/identifier this is already available in Lines 76 to 92 in ea9dc67
The main problem is that all classes are created in a dynamic way. So to solve this issue it's required to add a method in a hardcoded way. 😕 |
@Gummibeer Yes, the problem is the dynamic class structure. However, my solution works fine for me. |
And the most major problem I see is that this is something Google related and not the general schema standard. Or you extend the class and use this one in your code. |
Dear contributor, because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it. |
Hi I have been trying out your package and was trying to figure out breadcrumbs. Can you give a code example on how to set the @id parameter in each listitem? Here is the test code I have so far (currently I am using the thing type as a substitute)
What would be the php code needed to generate the JSON-LD example on Thanks |
A simple call to At all this is a tricky question. The code is auto generated by the schema XML - so there is no space/way for custom methods. The only way I see would be a special Google schema XML which adds the method to the breadcrumb-listitem. |
Based on the conversation above I figured I needed to use
Could you modify the code in my previous comment for an example? |
@eSilverStrike so far I see google has solved it now by their own: {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"name": "Books",
"item": "https://example.com/books"
},{
"@type": "ListItem",
"position": 2,
"name": "Authors",
"item": "https://example.com/books/authors"
},{
"@type": "ListItem",
"position": 3,
"name": "Ann Leckie",
"item": "https://example.com/books/authors/annleckie"
},{
"@type": "ListItem",
"position": 4,
"name": "Ancillary Justice",
"item": "https://example.com/books/authors/ancillaryjustice"
}]
} https://search.google.com/structured-data/testing-tool They auto-convert the string in For you this would be \Spatie\SchemaOrg\Schema::BreadcrumbList()
->itemListElement([
\Spatie\SchemaOrg\Schema::ListItem()
->position(1)
->name('Dresses')
->item('https://example.com/dresses'),
\Spatie\SchemaOrg\Schema::ListItem()
->position(2)
->name('Real Dresses')
->item('https://example.com/dresses/real'),
])
->toScript(); Your IDE will tell you that the value of \Spatie\SchemaOrg\Schema::BreadcrumbList()
->itemListElement([
\Spatie\SchemaOrg\Schema::ListItem()
->position(1)
->name('Dresses')
->item(
\Spatie\SchemaOrg\Schema::Thing()
->setProperty('@id', 'https://example.com/dresses')
),
\Spatie\SchemaOrg\Schema::ListItem()
->position(2)
->name('Real Dresses')
->item(
\Spatie\SchemaOrg\Schema::Thing()
->setProperty('@id', 'https://example.com/dresses/real')
),
])
->toScript(); This will have the Following https://schema.org/ListItem Just to complete the list: if you don't want the [
'@id' => 'https://example.com/dresses',
'name' => 'Dresses',
] This will generate exact what is in the example of the schema page. |
Thanks! |
Hi!
Great package!
I've found one thing to consider. If you want to build a BreadcrumbList schema, it's not valid by Google because they want a
@id
parameter in the ListItem.See: https://developers.google.com/search/docs/data-types/breadcrumb
I did not want to create a PR, because I do not exactly where this
@id
element should be assigned. It's not documented in schema.org, I think.Possible solution is to add a method on Thing.php:
Other solution is to create a new schema class
BreadcrumbListItem::class
and put the@id
property in there with extension ofListItem::class
Looking forward to your answer and happy coding! 👍
The text was updated successfully, but these errors were encountered: