Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete
[Redacted – I found a better way]
Last edited by michaelkpate (2020-07-06 13:55:16)
Offline
Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete
Hey Michael,
This would be an excellent one for txp.tips.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete
colak wrote #324278:
This would be an excellent one for txp.tips.
I will try to get something written up. I’ve made a few discoveries by installing this on a brand new site.
Offline
Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete
Version 5.0 (second try) – New for 2020, now with no PHP or additional plug-ins needed as it can all be done with native tags
Quick explanation of how this works on the Demo Site:
Textpattern no longer works the way it used to. You don’t need to do anything with the error template because everything is now generated by the default page template.
- Individual article – http://demo.cmsstyles.com/datebasedarchives/2020/07/06/date-based-archives
- Daily Archives – http://demo.cmsstyles.com/datebasedarchives/2020/07/06/
- Monthly Archives – http://demo.cmsstyles.com/datebasedarchives/2020/07/
- Yearly Archives – http://demo.cmsstyles.com/datebasedarchives/2020/
header-archives:
<txp:if_category><txp:else /><txp:variable name="page_date"><txp:page_url type="month" /></txp:variable></txp:if_category>
<txp:variable name="page_date_length"><txp:evaluate query=' string-length( "<txp:variable name=''page_date'' />" )' /></txp:variable>
<txp:if_variable name="page_date_length" value="10">
<txp:variable name="archivetype" value="daily" />
<txp:variable name="y"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 1, 4 )' /></txp:variable>
<txp:variable name="m"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 6, 2 )' /></txp:variable>
<txp:output_form form="month-title" />
<txp:variable name="d"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 9, 2 )' escape="tidy, integer, ordinal" /></txp:variable>
<txp:variable name="archivepagetitle" value='<txp:variable name="monthtitle" /> <txp:variable name="d" />, <txp:variable name="y" /> Articles | <txp:site_name />' />
<txp:variable name="archivetitle" value='Articles for the Day of <span><txp:variable name="monthtitle" /> <txp:variable name="d" />, <txp:variable name="y" /></span>' />
<txp:variable name="archivemonth" value='<txp:variable name="y" />-<txp:variable name="m" />-<txp:variable name="d" />' />
</txp:if_variable>
<txp:if_variable name="page_date_length" value="7">
<txp:variable name="archivetype" value="monthly" />
<txp:variable name="y"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 1, 4 )' /></txp:variable>
<txp:variable name="m"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 6, 2 )' /></txp:variable>
<txp:output_form form="month-title" />
<txp:variable name="archivepagetitle" value='<txp:variable name="monthtitle" /> <txp:variable name="y" /> Articles | <txp:site_name />' />
<txp:variable name="archivetitle" value='Articles for the Month of <span><txp:variable name="monthtitle" /> <txp:variable name="y" /></span>' />
<txp:variable name="archivemonth" value='<txp:variable name="y" />-<txp:variable name="m" />' />
</txp:if_variable>
<txp:if_variable name="page_date_length" value="4">
<txp:variable name="archivetype" value="yearly" />
<txp:variable name="y"><txp:evaluate query='substring("<txp:variable name=''page_date'' />", 1, 4 )' /></txp:variable>
<txp:variable name="archivetype" value="yearly" />
<txp:variable name="archivepagetitle" value='<txp:variable name="y" /> Articles | <txp:site_name />' />
<txp:variable name="archivetitle" value='Articles for the Year of <span><txp:variable name="y" /></span>' />
<txp:variable name="archivemonth" value='<txp:variable name="y" />' />
</txp:if_variable>
month-title:
<txp:if_variable name="m" value="01"><txp:variable name="monthtitle" value="January" /></txp:if_variable>
<txp:if_variable name="m" value="02"><txp:variable name="monthtitle" value="February" /></txp:if_variable>
<txp:if_variable name="m" value="03"><txp:variable name="monthtitle" value="March" /></txp:if_variable>
<txp:if_variable name="m" value="04"><txp:variable name="monthtitle" value="April" /></txp:if_variable>
<txp:if_variable name="m" value="05"><txp:variable name="monthtitle" value="May" /></txp:if_variable>
<txp:if_variable name="m" value="06"><txp:variable name="monthtitle" value="June" /></txp:if_variable>
<txp:if_variable name="m" value="07"><txp:variable name="monthtitle" value="July" /></txp:if_variable>
<txp:if_variable name="m" value="08"><txp:variable name="monthtitle" value="August" /></txp:if_variable>
<txp:if_variable name="m" value="09"><txp:variable name="monthtitle" value="September" /></txp:if_variable>
<txp:if_variable name="m" value="10"><txp:variable name="monthtitle" value="October" /></txp:if_variable>
<txp:if_variable name="m" value="11"><txp:variable name="monthtitle" value="November" /></txp:if_variable>
<txp:if_variable name="m" value="12"><txp:variable name="monthtitle" value="December" /></txp:if_variable>
default page:
<!DOCTYPE html>
<html lang="<txp:lang />" dir="<txp:text item="lang_dir" />">
<txp:output_form form="header-archives" escape="tidy, trim" />
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<txp:if_variable name="archivepagetitle" >
<title><txp:variable name="archivepagetitle" /></title>
<txp:else />
<title><txp:page_title /></title>
</txp:if_variable>
<!-- CSS -->
<txp:css format="link" media="" />
<!-- ...or you can use (faster) external CSS files e.g. <link rel="stylesheet" href="<txp:page_url type="theme_path" />/styles/default.css"> -->
<meta name="generator" content="Textpattern CMS">
<txp:if_search>
<meta name="robots" content="none">
<txp:else />
<txp:if_author>
<meta name="robots" content="noindex, follow">
<txp:else />
<txp:meta_description />
<txp:if_category>
<meta name="robots" content="noindex, follow">
<txp:else />
<txp:variable name="page" value='<txp:page_url type="pg" />' />
<txp:if_variable name="page" value="1">
<meta name="robots" content="index, follow">
<link rel="canonical" href="<txp:site_url />">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"headline": "<txp:site_name escape="json" />",
<txp:if_description>"description": "<txp:meta_description format="" escape="json" />",</txp:if_description>
"url": "<txp:site_url escape="json" />"
}
</script>
<txp:else />
<meta name="robots" content="noindex, follow">
</txp:if_variable>
<txp:variable name="front-page" value="1" />
</txp:if_category>
</txp:if_author>
</txp:if_search>
<meta name="year" content="<txp:variable name="y" />">
<meta name="month" content="<txp:variable name="m" />">
<meta name="day" content="<txp:variable name="d" />">
<meta name="monthtitle" content="<txp:variable name="monthtitle" />">
<!-- content feeds -->
<txp:feed_link flavor="atom" format="link" label="Atom" />
<txp:feed_link flavor="rss" format="link" label="RSS" />
</head>
<txp:if_variable name="front-page">
<body class="front-page" itemscope itemtype="https://schema.org/WebPage">
<txp:else />
<txp:if_search>
<body class="search-page" itemscope itemtype="https://schema.org/SearchResultsPage">
<txp:else />
<body class="listing-page" itemscope itemtype="https://schema.org/CollectionPage">
</txp:if_search>
</txp:if_variable>
<txp:output_form form="body_header" />
<div class="wrapper">
<div class="container">
<!-- Main content -->
<txp:if_variable name="archivepagetitle" >
<h1 itemprop="name"><txp:variable name="archivetitle" /></h1>
<txp:article class="article-list" form="article_listing" limit="10" wraptag="ul" />
<!-- ...or if you want to list all articles from all sections instead, then replace txp:article with txp:article_custom -->
<!-- add pagination links to foot of article listings if there are more articles available -->
<txp:evaluate test="newer,older">
<nav class="paginator" aria-label="<txp:text item="page_nav" />">
<txp:newer rel="prev">
<txp:text item="newer" />
</txp:newer>
<txp:older rel="next">
<txp:text item="older" />
</txp:older>
</nav>
</txp:evaluate>
<txp:else />
<main id="main" aria-label="<txp:text item="main_content" />" itemscope itemtype="https://schema.org/Blog">
<!-- is this the search result page? also omits the pagination links below (uses pagination format within search_display.txp instead) -->
<txp:if_search>
<txp:output_form form="search_display" />
<txp:else />
<!-- else is this the front page? -->
<txp:if_variable name="front-page">
<!-- links by default to form: 'default.txp' unless you specify a different form -->
<txp:article limit="5" />
<txp:else />
<!-- else is this an article author list? -->
<txp:if_author>
<h1 itemprop="name"><txp:text item="author" /> <txp:author /></h1>
<txp:else />
<!-- else is this an article category list? -->
<txp:if_category>
<h1 itemprop="name"><txp:text item="category" /> <txp:category title /></h1>
</txp:if_category>
</txp:if_author>
<txp:article form="article_listing" limit="10" wraptag="ul" class="article-list" />
</txp:if_variable>
<!-- add pagination links to foot of front page/author listings/category listings if there are more articles available -->
<txp:evaluate test="newer,older">
<nav class="paginator" aria-label="<txp:text item="page_nav" />">
<txp:newer rel="prev">
<txp:text item="newer" />
</txp:newer>
<txp:older rel="next">
<txp:text item="older" />
</txp:older>
</nav>
</txp:evaluate>
</txp:if_search>
</main>
</txp:if_variable>
<txp:output_form form="body_aside" />
</div> <!-- /.container -->
</div> <!-- /.wrapper -->
<txp:output_form form="body_footer" />
</body>
</html>
default article
<article class="article" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<meta itemprop="mainEntityOfPage" content="<txp:permlink />">
<txp:if_individual_article>
<h1 itemprop="headline"><txp:title /></h1>
<txp:else />
<h1 itemprop="headline"><a href="<txp:permlink />" itemprop="url" title="<txp:text item="read_more" />"><txp:title /></a>
</h1>
</txp:if_individual_article>
<p>
<strong>
<txp:text item="posted" />
</strong>
<time datetime="<txp:posted format="iso8601" />" itemprop="datePublished">
<a href="<txp:site_url /><txp:posted format="%Y" />" itemprop=""><txp:posted format="%Y" /></a>
<a href="<txp:site_url /><txp:posted format="%Y/%m" />" itemprop=""><txp:posted format="%B" /></a>
<a href="<txp:site_url /><txp:posted format="%Y/%m/%d" />" itemprop=""><txp:posted format="%e" /></a>
</time>
<meta itemprop="dateModified" content="<txp:modified format="iso8601" />" />
<!-- only display comments count if comments posted, or if new comments allowed -->
<txp:if_comments>
<br>
<strong>
<txp:text item="comments" />
</strong>
<a href="<txp:permlink />#comments-head" title="<txp:text item="view" />" itemprop="discussionUrl">
<span itemprop="interactionStatistic" itemscope itemtype="https://schema.org/InteractionCounter">
<meta itemprop="interactionType" content="https://schema.org/CommentAction" />
<span itemprop="userInteractionCount"><txp:comments_count /></span>
</span>
</a>
<txp:else />
<txp:if_comments_allowed>
<br>
<strong>
<txp:text item="comments" />
</strong>
<a href="<txp:permlink />#comments-head" title="<txp:text item="view" />" itemprop="discussionUrl">
<span itemprop="interactionStatistic" itemscope itemtype="https://schema.org/InteractionCounter">
<meta itemprop="interactionType" content="https://schema.org/CommentAction" />
<span itemprop="userInteractionCount">0</span>
</span>
</a>
</txp:if_comments_allowed>
</txp:if_comments>
</p>
<txp:if_article_image>
<txp:images form="images" />
</txp:if_article_image>
<div itemprop="articleBody">
<txp:body />
</div>
<p>
<strong>
<txp:text item="author" />
</strong>
<span itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">
<txp:author link this_section />
</span>
</span>
<!-- only display categories if they are actually set for an article, otherwise omit -->
<txp:if_article_category>
<br>
<strong>
<txp:text item="categories" />
</strong>
<span itemprop="keywords">
<txp:category_list categories='<txp:category1 />,<txp:category2 />' children="0" break=", " trim>
<txp:category title link />
</txp:category_list>
</span>
</txp:if_article_category>
</p>
<!-- if this is an individual article then add the comments section via form: comments_display.article.txp -->
<txp:if_individual_article>
<txp:output_form form="comments_display" />
</txp:if_individual_article>
</article>
article_listing
<li class="article" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<h4 itemprop="headline">
<a href="<txp:permlink />" itemprop="url mainEntityOfPage" title="<txp:text item="read_more" />">
<txp:title />
</a>
</h4>
<!-- if the article has an excerpt, display that -->
<txp:if_excerpt>
<div itemprop="description">
<txp:excerpt />
</div>
</txp:if_excerpt>
<p class="footnote">
<txp:text item="posted" />
<time datetime="<txp:posted format="iso8601" />" itemprop="datePublished">
<a href="<txp:site_url /><txp:posted format="%Y" />" itemprop=""><txp:posted format="%Y" /></a>
<a href="<txp:site_url /><txp:posted format="%Y/%m" />" itemprop=""><txp:posted format="%B" /></a>
<a href="<txp:site_url /><txp:posted format="%Y/%m/%d" />" itemprop=""><txp:posted format="%e" /></a>
</time>
<meta itemprop="dateModified" content="<txp:modified format="iso8601" />" />
·
<txp:text item="author" />
<span itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">
<txp:author link this_section />
</span>
</span>
</p>
</li>
This version is now based on default template from 4.8.1.
Offline