当前位置: 首页>>代码示例>>PHP>>正文


PHP Article::byTag方法代码示例

本文整理汇总了PHP中app\Article::byTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::byTag方法的具体用法?PHP Article::byTag怎么用?PHP Article::byTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Article的用法示例。


在下文中一共展示了Article::byTag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: index

 /**
  * Display sitemap.xml
  *
  * @return Response
  */
 public function index()
 {
     $sitemap = App::make("sitemap");
     if (!$sitemap->isCached()) {
         // main page
         $home = URL::to('/');
         $sitemap->add($home, date('c', time()), '1.0', 'daily');
         $perPage = 15;
         // tags
         foreach (config('sitemap.tags') as $tag => $label) {
             $url = route('tag', $tag);
             $sitemap->add($url, date('c', time()), '0.7', 'weekly');
             // pages of tag
             $pages = ceil(Article::byTag($tag)->count() / $perPage);
             if ($pages > 1) {
                 for ($page = 2; $page <= $pages; $page++) {
                     $sitemap->add("{$url}/page/{$page}", date('c', time()), '0.7', 'weekly');
                 }
             }
         }
         // all posts
         $posts = Article::all();
         foreach ($posts as $post) {
             if ($post->path) {
                 $url = route('post', $post->path);
             } else {
                 $url = route('post_by_id', $post->id);
             }
             $date = max(strtotime($post->created_at), strtotime($post->updated_at));
             $sitemap->add($url, date('c', $date), '0.9', 'daily');
         }
         // archive pages
         $pages = ceil(count($posts) / $perPage);
         if ($pages > 1) {
             for ($page = 2; $page <= $pages; $page++) {
                 $sitemap->add("{$home}/page/{$page}", date('c', time()), '0.8', 'daily');
             }
         }
     }
     return $sitemap->render('xml');
 }
开发者ID:Hukuta,项目名称:laravel-blog,代码行数:46,代码来源:SitemapController.php

示例2: show

 public function show($tag, Request $request)
 {
     $article = Article::byTag($tag);
     return view('article.show', compact('article', 'tag'));
 }
开发者ID:sandywalker,项目名称:xiehouxing,代码行数:5,代码来源:ArticleController.php

示例3: tag

 public function tag(Request $request, $tag, $page = 1)
 {
     // changing pagination page from route param
     Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     // getting articles
     $articles = Article::byTag($tag)->paginate();
     // changing routing in rendered pagination view
     $pagination_view = $articles->render();
     // from "/tag/$tag/?page=$page" to "/tag/$tag/page/$page"
     $pagination_view = preg_replace('|/(page/\\d+/?)?\\?page=(\\d+)|', '/page/$2', $pagination_view);
     // replace "/tag/$tag/page/1" to "/tag/$tag"
     $pagination_view = str_replace('/page/1"', '"', $pagination_view);
     //redirect from $_GET paging to new routing
     $_page = $request->get('page');
     if ($_page && (string) abs($_page) === $_page) {
         if ($_page == 1) {
             return redirect(route('tag', $tag));
         }
         return redirect(route('tag_paged', [$tag, $_page]));
     }
     $page_title = 'Блог веб разработчика: ' . $tag;
     $view = $request->ajax() ? 'articles.index-content' : 'articles.index';
     if (!$articles->count()) {
         abort(404);
     }
     // image for og meta
     $tag_image = url('/images/logo.png');
     foreach ($articles as $article) {
         $found_image = $article->getImageUrl();
         if ($found_image != $tag_image) {
             $tag_image = $found_image;
             break;
         }
     }
     return response()->view($view, compact('articles', 'page_title', 'pagination_view', 'page', 'tag', 'tag_image'))->withCookie($this->rating_cookie($request));
 }
开发者ID:Hukuta,项目名称:laravel-blog,代码行数:38,代码来源:ArticlesController.php


注:本文中的app\Article::byTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。