From ac712052a8cbaabff32eacb41171690659b598b7 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 23 May 2018 17:43:18 +0700 Subject: [PATCH] Add blog templates for blog module --- site/templates/blog-post.php | 59 +++++++++++++++++++++++++++++++++++ site/templates/blog-posts.php | 31 ++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100755 site/templates/blog-post.php create mode 100755 site/templates/blog-posts.php diff --git a/site/templates/blog-post.php b/site/templates/blog-post.php new file mode 100755 index 0000000..cf1bf64 --- /dev/null +++ b/site/templates/blog-post.php @@ -0,0 +1,59 @@ +get("MarkupBlog"); + + // subnav + $subNav = ''; + + // subnav: get date info for creating link to archives page in subnav + $date = $page->getUnformatted('blog_date'); + $year = date('Y', $date); + $month = date('n', $date); + + // subnav: if there are categories and/or tags, then make a separate nav for them + if(count($page->blog_categories)) $subNav .= $blog->renderNav(__('Related Categories'), $page->blog_categories); + if(count($page->blog_tags)) $subNav .= $blog->renderNav(__('Related Tags'), $page->blog_tags); + + // subnav: contains authors, archives and categories links + $authorsURL = $pages->get('template=blog-authors')->url; + $archivesURL = $pages->get('template=blog-archives')->url; + // use pageName sanitized author title as PART of URL, else empty + $authorURL = $sanitizer->pageName($page->createdUser->title) ? $sanitizer->pageName($page->createdUser->title) . '/' : ''; + $authorName = $page->createdUser->title ? $page->createdUser->title : 'Author Name';//use generic 'Author Name' if author title not yet set + + $subNavItems = array( + $authorsURL . $authorURL => $authorName, + $archivesURL . $year . "/" . $month . "/" => strftime('%B %Y', $date) + ); + + $subNav .= $blog->renderNav(__('See Also'), $subNavItems); + + // main content + + // render a single full post including title, comments, comment form + next/prev posts links, etc + // $blog->postAuthor(): if available, add 'post author widget' at the end (or at the top if desired) of each post + // $content = $blog->renderPosts($page) . $blog->renderComments($page->blog_comments) . $blog->renderNextPrevPosts($page);//without post author + + /* + for this demo, renderComments() has to adapt to whether blog commenting feature was installed or not whilst remaining blog structure/style-agnostic + in your own blog install, you would know if you enabled the feature so there would be no need for such a check + in addition, our 'check' code is not code you would normally use in a template file. + we use such code here to be both foolproof that the commenting feature is installed and blog structure-agnostic + */ + #not foolproof; user could have post-installed custom commenting feature (e.g. Disqus) with a similar field blog_comments + // $renderComments = $page->template->hasField('blog_comments') ? $blog->renderComments($page->blog_comments) : ''; + + $blogConfigs = $modules->getModuleConfigData('ProcessBlog'); + + $renderComments = $blogConfigs['commentsUse'] == 1 ? $blog->renderComments($page->blog_comments) : ''; + // with post author widget + $content = $blog->renderPosts($page) . $blog->postAuthor() . $renderComments . $blog->renderNextPrevPosts($page); + + diff --git a/site/templates/blog-posts.php b/site/templates/blog-posts.php new file mode 100755 index 0000000..ff776e1 --- /dev/null +++ b/site/templates/blog-posts.php @@ -0,0 +1,31 @@ +get("MarkupBlog"); + + // main content + $content = ''; + $content .= "

{$page->get('blog_headline|title')}

"; + //render a limited number of summarised posts + $content .= $blog->renderPosts("limit=5", true); + + // rss + /** Note, for the RSS to work, you should not output anything further after calling this, as it outputs the RSS directly. If not, you will get an error **/ + + // if we want to view the rss of posts + if($input->urlSegment1) { + // rss feed + if($input->urlSegment1 != 'rss') throw new Wire404Exception(); + $homepage = $pages->get('/'); + //render rss; just an example...we have no meta_description field + $blog->renderRSS($page->children("limit=10"), $homepage->get('headline|title'), $homepage->get('summary|meta_description')); + return;// this is important: stops output of any other markup except the RSS xml + } + +