简体   繁体   English

laravel 5 中的站点地图生成器,带有 RoumenDianoff 站点地图

[英]Site map generator in laravel 5 with RoumenDianoff sitemap

Im implementing the laravel RoumenDianoff Sitemap in my application我在我的应用程序中实现了 laravel RoumenDianoff 站点地图

https://github.com/RoumenDamianoff/laravel-sitemap/wiki/Dynamic-sitemap https://github.com/RoumenDamianoff/laravel-sitemap/wiki/Dynamic-sitemap

And im really confused on this part of the code我真的很困惑这部分代码

Route::get('sitemap', function(){

// create new sitemap object
$sitemap = App::make("sitemap");

// set cache key (string), duration in minutes (Carbon|Datetime|int), turn on/off (boolean)

$sitemap->setCache('laravel.sitemap', 60);

$posts = DB::table('posts')->orderBy('created_at', 'desc')->get();


     foreach ($posts as $post)
     {
        $sitemap->add($post->slug, $post->modified, $post->priority, $post->freq);
     }

As I understand i'm creating a route to use sitemap as that function so the part I don't get is when do I iterate trough every link of my website, or how do i get this links from my website to add then to the for each on that function, i mean it looks like that $posts variable but I don't have record of my links on any database so how can i get this links.据我所知,我正在创建一条路线来使用站点地图作为该功能,所以我没有得到的部分是我何时遍历我网站的每个链接,或者如何从我的网站获取此链接然后添加到对于每个函数,我的意思是它看起来像 $posts 变量,但我没有在任何数据库上记录我的链接,所以我怎么能得到这个链接。

What I would do is generate the links dynamically (probably using values from the database).我要做的是动态生成链接(可能使用数据库中的值)。 Then create a sitemap object that will be populated with all the links (use foreach loop) and finally store this.然后创建一个站点地图对象,该对象将填充所有链接(使用 foreach 循环)并最终存储它。 Check out the code fragment below:查看下面的代码片段:

Route::get('sitemap',function(){

    // Generate your links dynamically here
    $link = [];
    $locations = DB::locations(); /** some database values **/

    foreach($locations as $location){
        $link = route('home') . '/shoes-for-sale-in-' . strtolower($location);

        // create new sitemap object
        $sitemap = \App::make("sitemap");

        // Add link, priority,last modified and change frequency
        $sitemap->add($link, null, 0.5, 'monthly');

    }

    // generate sitemap (format, filename)
    $sitemap->store('xml', 'commercial');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM