elephpant / structured-data
结构化数据(schema.org)是一套可扩展的架构,使得网站管理员和开发者更容易在网页上嵌入结构化数据,供搜索引擎和其他应用程序使用。
dev-master
2020-03-16 17:10 UTC
Requires
- php: ^7.1
- ext-json: *
This package is auto-updated.
Last update: 2024-09-17 03:17:42 UTC
README
结构化数据(schema.org)是一套可扩展的架构,使得网站管理员和开发者更容易在网页上嵌入结构化数据,供搜索引擎和其他应用程序使用。
结构化数据(schema.org)是一套可扩展的架构,使得网站管理员和开发者更容易在网页上嵌入结构化数据,供搜索引擎和其他应用程序使用。
亮点
- 简单安装(简单安装)
- Composer就绪且符合PSR-2规范(准备好Composer且符合PSR-2规范)
安装
结构化数据可通过Composer获得
"elephpant/structured-data": "dev-master"
或运行
composer require elephpant/structured-data:dev-master
文档
有关使用方法的详细信息,请参阅组件目录中的示例文件夹。其中包含了每个类的使用示例。它的工作方式如下
有关如何使用的更多详细信息,请参阅组件目录中的示例文件夹。其中包含了每个类的使用示例。它的工作方式如下
开始网页
<?php require __DIR__ . "/../vendor/autoload.php"; use ElePHPant\StructuredData\WebPage; $webPage = new WebPage(); $webPage->start( 'Wayne Enterprises, Inc.', 'Wayne Enterprises is a big, growing multinational company', 'https://www.yourdomain.com/wayne-enterprises.jpg', 'https://www.dccomics.com', 'en-US' ); $webPage->isPartOf( 'https://www.yourdomain.com/logo.png', 'https://www.yourdomain.com/logo.png' ); $webPage->about( 'https://www.yourdomain.com/logo.png' ); $webPage->creator( 'https://www.yourdomain.com/logo.png', 'Gotham City', 'DC', '12345-678', '1007 Mountain Drive', 'Bruce Wayne', 'https://gravatar.com/avatar', [ 'https://#/zuck', 'https://www.instagram.com/zuck' ] );
博客帖子
<?php require __DIR__ . "/../vendor/autoload.php"; use ElePHPant\StructuredData\BlogPosting; /** * SINGLE POST EXAMPLE */ $post = new \stdClass(); $post->title = "It's not who I am underneath but what I do that defines me."; $post->slug = "it-s-not-who-i-am-underneath-but-what-i-do-that-defines-me"; $post->subtitle = "Bruce Wayne, eccentric billionaire. No guns, no killing. Swear to me! I'm Batman"; $post->content = "<h3>I'm Batman</h3><p>Bats frighten me.</p><p>It's time my enemies shared my dread.</p>"; $post->post_date = "2020-12-30"; $post->post_modified = "2020-12-31"; $post->cover = "images/2020/12/it-s-not-who-i-am-underneath-but-what-i-do-that-defines-me.jpg"; /** * Schema: BlogPosting * @link https://schema.org/BlogPosting */ $blogPosting = new BlogPosting($webPage); $blogPosting->start($post->title, $post->subtitle, $post->content, $post->post_date, $post->post_modified); $blogPosting->image("https://www.yourdomain.com/storage/{$post->cover}"); $blogPosting->mainEntityOfPage("https://www.yourdomain.com/blog/{$post->slug}"); $blogPosting->publisher('https://www.yourdomain.com/logo.png'); $blogPosting->author('Bruce Wayne', 'https://gravatar.com/avatar', [ 'https://#/zuck', 'https://www.instagram.com/zuck' ]);
渲染JSON
<?php echo $blogPosting->render(); // {"@context":"http://schema.org","@type": ...
渲染JSON-LD自动脚本标签
<?php echo $blogPosting->render(true); // <script type="application/ld+json">{"@context":"http://schema.org","@type": ... </script>
手动渲染JSON脚本标签
<script type="application/ld+json"> <?= $blogPosting->render(); ?> // {"@context":"http://schema.org","@type": ... </script>
调试
<?php $blogPosting->debug();
贡献
请参阅CONTRIBUTING以获取详细信息。
支持
安全:如果您发现任何安全相关的问题,请通过电子邮件agencia@uebi.com.br报告,而不是使用问题跟踪器。
如果您发现任何与安全相关的问题,请通过电子邮件agencia@uebi.com.br报告,而不是使用问题跟踪器。
谢谢
鸣谢
- Wilder Amorim(开发者)
- Sérgio Danilo Jr.(开发者)
- Agência Uebi(团队)
- 所有贡献者(这座岩石)
许可
MIT许可证(MIT)。请参阅许可文件以获取更多信息。