-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1google_news_sitemap_test.php
65 lines (51 loc) · 2.95 KB
/
1google_news_sitemap_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
use Dialeleven\PhpGoogleSitemap;
include_once $_SERVER['DOCUMENT_ROOT'] . '/src/GoogleNewsSitemap.php';
/*
Instantiate the PHP Google News Sitemap Class. Pass your hostname below as an
argument using PHP's $_SERVER['HTTP_HOST'] or you can hard code your hostname
such as 'https://www.yourdomain.com' for example.
*** DO NOT INCLUDE A TRAILING SLASH AT THE END OF YOUR HOSTNAME! ***
*/
$my_sitemap = new Dialeleven\PhpGoogleSitemap\GoogleNewsSitemap($sitemap_type = 'news',
$http_hostname = 'www.testdomain.com',
$xml_files_dir = $_SERVER['DOCUMENT_ROOT'] . '/public/sitemaps');
/*
Some configuration methods for your sitemap file(s) to be generated.
*/
#$my_sitemap->setXmlMode($mode = 'file'); // For development purposes. mode = memory (browser), mode = file (save to XML file)
$my_sitemap->setUseHttpsUrls(true); // use "https" mode for your URLs or plain "http"
$my_sitemap->setSitemapFilenamePrefix('mynews_sitemap'); // set name of sitemap file minus ".xml" (e.g. mysitemap.xml)
$my_sitemap->setUseGzip($use_gzip = true); // gzip the urlset files to reduce file sizes (true/false). NOTE: using gzip will unlink() (i.e. delete) the original XML file(s) after.
// Start adding your URLs and news items
for ($i = 1; $i <= 110000; ++$i)
{
echo $i . ' - ';
/*
Add URLs from your database or array (if preferred)
1. $loc - Should not include the hostname. For example if the URL is https://www.yourdomain.com/somepath/, then
the $loc should be "somepath/" if you want the trailing slash. Trailing slash is not enforced for
flexibility as some sites may not use a trailing slash.
2. $tags_arr - here pass an array of news URL including the following:
- name (required)
- language (required)
- publication_date (required)
- title (required)
The class will create a new 'urlset' file if you reach the 50,000 URL limit and create
the 'sitemapindex' file listing each urlset file that was generated.
*/
$my_sitemap->addUrl(
$loc = "url-$i/",
$tags_arr = array(
// name/language/publication_date/title are required
'name' => "The Example Times",
'language' => 'en',
'publication_date' => '2024-04-19',
'title' => "Example Article Title #$i"
)
);
}
// signal when done adding URLs, so we can generate the sitemap index file (table of contents)
$my_sitemap->endXmlDoc();
#throw new Exception('Test exception here');
#throw new InvalidArgumentException('test');