Bagaimana cara menggunakan hook untuk meng-custom schema urlset/sitemapindex di ekstensi Sitemap? #300
Unanswered
bungfrangki
asked this question in
Q&A
Replies: 1 comment
-
|
Kait layout kebanyakan mengikuti saran yang telah Saya tuliskan di artikel ini, jadi semua ekstensi yang menghasilkan markup HTML/XML pada umumnya akan dikenai kait semacam itu: <?php
Hook::set('y.sitemap', function ($y) use ($site) {
if ('urlset' !== ($y[0] ?? 0)) {
return $y;
}
if (!is_array($y[1] ?? 0)) {
return $y;
}
foreach ($y[1] as $k => $v) {
if (!$k || !is_file($k)) {
continue;
}
// Since version 3.0.4, `$k` holds the file path of the item
$page = new Page($k);
$y[1][$k][1][] = [
0 => 'news:news',
1 => [
['news:publication', [
['news:language', $site->language ?? 'en', []],
['news:name', $site->title . ($page->parent ? ': ' . $page->parent->title : ""), []]
], []],
['news:publication_date', $page->time('%Y-%m-%d'), []],
['news:title', $page->title, []]
],
2 => []
];
if ($images = array_unique(array_filter(array_merge((array) $page->images, [$page->image])))) {
foreach ($images as $image) {
$y[1][$k][1][] = [
0 => 'image:image',
1 => [
['image:loc', $image, []]
],
2 => []
];
}
}
// β¦
}
if (!is_array($y[2] ?? 0)) {
return $y;
}
$y[2]['xmlns:image'] = 'http://www.google.com/schemas/sitemap-image/1.1';
$y[2]['xmlns:news'] = 'http://www.google.com/schemas/sitemap-news/0.9';
$y[2]['xmlns:video'] = 'http://www.google.com/schemas/sitemap-video/1.1';
$y[2]['xmlns:xhtml'] = 'http://www.w3.org/1999/xhtml';
return $y;
});Silakan perbarui ekstensi mecha-cms/x.sitemap ke versi 3.0.4, agar bisa menambahkan item baru dengan mudah, karena sejak versi tersebut setiap key item akan berisi jalur berkasnya. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
misalnya saya ingin menggunakan urlset seperti ini:
namun di sitemapindex pakai schema yang seperti ini:
Beta Was this translation helpful? Give feedback.
All reactions