graph creation
mesutuca33 opened this issue · comments
hello, I'm new among you and I don't understand much, frankly, how to open the event or how the graph is arranged. please i want to do the following can you help me
<script type="application/ld+json" class="yoast-schema-graph">{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://www.dugunalbumleri.com/#organization",
"name": "HTC Alb\u00fcm",
"url": "https://www.dugunalbumleri.com/",
"sameAs": [
"https://www.facebook.com/htcalbum",
"https://www.instagram.com/htcalbum"
],
"logo": {
"@type": "ImageObject",
"@id": "https://www.dugunalbumleri.com/#logo",
"inLanguage": "tr",
"url": "https://www.dugunalbumleri.com/wp-content/uploads/2018/03/470x110.png",
"width": 232,
"height": 54,
"caption": "HTC Alb\u00fcm"
},
"image": {
"@id": "https://www.dugunalbumleri.com/#logo"
}
},
{
"@type": "WebSite",
"@id": "https://www.dugunalbumleri.com/#website",
"url": "https://www.dugunalbumleri.com/",
"name": "D\u00fc\u011f\u00fcn Alb\u00fcmleri",
"description": "",
"publisher": {
"@id": "https://www.dugunalbumleri.com/#organization"
},
"potentialAction": [
{
"@type": "SearchAction",
"target": "https://www.dugunalbumleri.com/?s={search_term_string}",
"query-input": "required name=search_term_string"
}
],
"inLanguage": "tr"
},
{
"@type": "WebPage",
"@id": "https://www.dugunalbumleri.com/#webpage",
"url": "https://www.dugunalbumleri.com/",
"name": "D\u00fc\u011f\u00fcn Alb\u00fcm\u00fc | Panoramik D\u00fc\u011f\u00fcn Alb\u00fcmleri | HTC Alb\u00fcm",
"isPartOf": {
"@id": "https://www.dugunalbumleri.com/#website"
},
"about": {
"@id": "https://www.dugunalbumleri.com/#organization"
},
"datePublished": "2018-03-24T20:16:53+00:00",
"dateModified": "2020-02-04T20:33:08+00:00",
"description": "D\u00fc\u011f\u00fcn Alb\u00fcm\u00fc modellerini ke\u015ffedin! Favori D\u00fc\u011f\u00fcn Alb\u00fcm\u00fc tasar\u0131m\u0131n\u0131z\u0131 se\u00e7in. D\u00fc\u011f\u00fcn Alb\u00fcmleri modelleri, fiyatlar\u0131, \u00f6zellikleri. D\u00fc\u011f\u00fcn Alb\u00fcm imalat\u0131 burada.",
"inLanguage": "tr",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://www.dugunalbumleri.com/"
]
}
]
}
]
}</script>
I see this is the snippet of schema added by Yoast WordPress plugin.
What exactly you want?
okay it is not possible to do this in php?
Yes, It is possible.
This git repo is for PHP.
Yoast is a WordPress plugin which is written in php.
My question is what exactly you want to do, then we may help you.
If you are asking whether the above schema snippet can be generated by this repo, then the answer is Yes.
For answer to "how", you may check this article:
https://freek.dev/642-a-package-to-fluently-generate-schemaorg-markup
and repo readme: https://github.com/spatie/schema-org/blob/master/README.md
okay it is not possible to do this in php?
I want to be the sameAs array.
potentialAction ??
Can you give me an example of how to write? I don't know much
$graph
->organization()
->identifier('https://www.dugunalbumleri.com/#organization')
->name('ALBUM')
->url('https://www.dugunalbumleri.com/')
->sameAs('https://www.facebook.com/htcalbum');
$graph
->webSite()
->identifier('https://www.dugunalbumleri.com/#website')
->url('https://www.dugunalbumleri.com/')
->name('Düğün Albümleri')
->description('AÇIKLAMA');
// Render graph to script tag
echo $graph;
As far as i know, these properties are not of the Graph.
graph is a collection (array) of different schema.
So, in your case, the following should work:
$organization
->organization()
->identifier('https://www.dugunalbumleri.com/#organization')
->name('ALBUM')
->url('https://www.dugunalbumleri.com/')
->sameAs('https://www.facebook.com/htcalbum');
$website
->webSite()
->identifier('https://www.dugunalbumleri.com/#website')
->url('https://www.dugunalbumleri.com/')
->name('Düğün Albümleri')
->description('AÇIKLAMA');
$graph = [$organization , $website ]
I guess you got it wrong. What I want to do is the example below
$graph = new Graph();
$graph
->organization()
->identifier('https://www.dugunalbumleri.com/#organization')
->name('ALBUM')
->url('https://www.dugunalbumleri.com/')
->sameAs('https://www.facebook.com/htcalbum');
$graph
->webSite()
->identifier('https://www.dugunalbumleri.com/#website')
->url('https://www.dugunalbumleri.com/')
->name('Düğün Albümleri')
->description('AÇIKLAMA');
// Render graph to script tag
echo $graph;
<script type="application/ld+json">{
"@context": "https:\/\/schema.org",
"@graph": [
{
"@type": "Organization",
"name": "ALBUM",
"url": "https:\/\/www.dugunalbumleri.com\/",
"sameAs": "https:\/\/www.facebook.com\/htcalbum",
"@id": "https:\/\/www.dugunalbumleri.com\/#organization"
},
{
"@type": "WebSite",
"url": "https:\/\/www.dugunalbumleri.com\/",
"name": "Düğün Albümleri",
"description": "AÇIKLAMA",
"@id": "https:\/\/www.dugunalbumleri.com\/#website"
}
]
}</script><!DOCTYPE html>
how do i do webSite ()
"potentialAction": [
{
"@type": "SearchAction",
"target": "https://www.dugunalbumleri.com/?s={search_term_string}",
"query-input": "required name=search_term_string"
}
],
and
"sameAs": [
"https://www.facebook.com/htcalbum",
"https://www.instagram.com/htcalbum"
],
Hey,
you can add these things to the website by calling the methods on it.
$graph->website()
->potentialAction(
Schema::searchAction()
->target("https://www.dugunalbumleri.com/?s={search_term_string}")
->queryInput("required name=search_term_string")
)
->sameAs([
"https://www.facebook.com/htcalbum",
"https://www.instagram.com/htcalbum"
])
Thank you for your answer. I have a problem right now I will show as an example so that it can be understood better
$data['type'] ="Collection"
If type is Collection
"@type": "CollectionPage",
i want to print
The type is usually collection or normal and I'll print it accordingly.
$graph
**->webPage()**
->identifier($data['url'] . '/#webpage')
->url($data['url'])
->name($data['title'])
->isPartOf(array("@id" => $data['url'] . '/#website'))
->primaryImageOfPage(array("@id" => $data['url'] . '/#primaryimage'))
->datePublished($data['date'])
->dateModified($data['update'])
->description($data['description'])
->inLanguage('tr')
->potentialAction(
Schema::readAction()
->target("https://www.dugunalbumleri.com/")
);
```
You could use getOrCreate()
which s the underlying method of all the shorthand. But you will lose autocompletion or you can use the if()
method which will keep up autocompletion but duplicate your code.
The autocompletion could be solved by using a variable and php-doc.
/** @var WebPage|CollectionPage $webpage */
$webpage = $graph->getOrCreate(
$data['type'] === "Collection"
? CollectionPage::class
: WebPage::class
);
$webpage
->identifier($data['url'] . '/#webpage')
;
Lines 966 to 977 in a10abbf
you are great man.
finally $data['photo'] = "images15x15.jpg
If it is blank, I don't want the following line to be written. Is it possible to write without calling fuction? I would be very happy if you give an example.
If the image is empty I want to disable the image Object and primary mage Page.
-> primaryImageOfPage (array ("@ id" => $ data ('url'). '/ # primaryimage'))
$graph
->imageObject()
->identifier($data['url'] . '/#primaryimage')
->inLanguage('tr')
->url($data['photo'])
->width(1920)
->height(1281)
->caption('Düğün Modelleri');
$webpage = $graph->getOrCreate(
$data['type'] === "koleksiyon" ? \Spatie\SchemaOrg\CollectionPage::class : \Spatie\SchemaOrg\WebPage::class
);
$webpage
->identifier($data['url'] . '/#webpage')
->url($data['url'])
->name($data['title'])
->isPartOf(array("@id" => $data['url'] . '/#website'))
->primaryImageOfPage(array("@id" => $data['url'] . '/#primaryimage'))
->datePublished($data['date'])
->dateModified($data['update'])
->description($data['description'])
->inLanguage('tr')
->potentialAction(
Schema::readAction()
->target("https://www.dugunalbumleri.com/")
);
```
$graph->type()
->if($data['photo'], function(Type $type) {
// Do something with your type
});
I got an error.
Fatal error: Uncaught BadMethodCallException: The method "type" does not exist on class "Spatie\SchemaOrg\Graph". in C:\xampp\htdocs\app\3rd-party-apps\schema-org\src\Graph.php:922 Stack trace: #0 C:\xampp\htdocs\app\classes\snippet.php(306): Spatie\SchemaOrg\Graph->__call('type', Array) #1 C:\xampp\htdocs\app\controller\index.php(32): snippet::NewOrganization(Array) #2 C:\xampp\htdocs\index.php(34): require('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\app\3rd-party-apps\schema-org\src\Graph.php on line 922
$graph->type()
->if($data['photo'], function (Type $type) {
$graph
->imageObject()
->identifier($data['url'] . '/#primaryimage')
->inLanguage('tr')
->url($data['photo'])
->width(1920)
->height(1281)
->caption('Düğün Modelleri');
});
type()
was a placeholder for any possible type you could create on the graph.
Sorry for that. So eg $graph->person()->if()
I did not understand anything. I am getting the error how to use it. Is it possible to show you an example of use?
### As an example I want to ask like this.
If "data ['photo']" is empty, do not write "image Object" function in any way.
and not write "primaryImageOfPage" in "$ webpag".
Has anyone ever used this before?
$graph
->imageObject()
->identifier($data['url'] . '/#primaryimage')
->inLanguage('tr')
->url($data['photo'])
->width(1920)
->height(1281)
->caption('Düğün Modelleri');
I know that way I can disable the primary Image Page. but "$ graph
-> How can I remove imageObject () "?
$business = ['url' => $data['url']];
$webpage->if(isset($data['photo']), function (Type $type) use ($business) {
$type->primaryImageOfPage(array("@id" => $business['url'] . '/#primaryimage'));
});
Do you think it is correct to remove it this way?
if ($data['photo']):
$graph
->imageObject()
->identifier($data['url'] . '/#primaryimage')
->inLanguage('tr')
->url($data['photo'])
->caption($data['description']);
endif;
This if
is totally fine. If you like methods and closures more the same if()
method from your primary image example is also available on the $graph
itself.
I understood thank you. One last question is should I add json data to the bottom of the page or to the top?
I usually add it as the last element as the schema definition can get really big and HTML is processed from top to bottom, so it doesn't delay my rendering and so on.
But I don't know if there's any real rule/advice.
Thank you for your answer.
I did it this way, there was no problem with the organization, but I want to add place and LocalBusiness as grap typena, how can I get it?
note i want to do this in Graph.
i made
$graph = new Graph();
$graph
->organization()
"@graph": [
{
"@type": "Organization",
the content I want
"@graph": [
{
"@type": [
"Organization",
"Place",
"LocalBusiness"
],
There's no need for an MTE here. LocalBusiness
extends Place
and Organization
.
https://schema.org/LocalBusiness
So use LocalBusiness
only and everything is fine.
#147 was about MTEs and there's also an official link that describes when to use MTEs.
I don't understand the subject "@type": ["Organization", "Place", "Local Business"],
Isn't it a problem if you write separately?
Can't I do this on graph, not Mte?
There's absolutely no need as LocalBusiness
is already a place and also an organization. See the official schema link. And it's also implemented like this in the package.
So defining your local business via MTE as all three of them will only hurt you. As not all readers understand it/can parse it and the other types in the MTE are also not different.
well place? do not need that too? Does it hurt if I write it as graph?