Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2014-10-29 17:15:14

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete

ingleslenobel wrote #285221:

Cool, I guessed right:)

In truth I’m completely new to textpattern and hadn’t realised that I needed to change the permanent link mode to use this. Doing so is a bit of a problem for me from the SEO point of view sadly.

What I’m really after is the ability for users to browse to articles several ways. By category, and by date but all those having a permanent url which uses the title. Ie a topnav item that says archives, that goes to some page which has a treelike list descending by date, and the items link to /pagetitle/ pages, with the latter being the permanent link.

Does that make sense – does your work do something like this or am I way off :)

Thank you

Actually you don’t have to – as I found out a little earlier. If you land on a url like year/month this will still work. I just tend to think of people hand-altering Urls wp-style by maybe I am the only one that does that.

There is definitely nothing stopping you from doing a single page – that was the first method I came up with. When I have some free time later, I’ll take a look at how to setup that up again.

Offline

#14 2014-10-29 17:25:03

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete

michaelkpate wrote #285222:

Actually you don’t have to – as I found out a little earlier. If you land on a url like year/month this will still work. I just tend to think of people hand-altering Urls wp-style by maybe I am the only one that does that.

There is definitely nothing stopping you from doing a single page – that was the first method I came up with. When I have some free time later, I’ll take a look at how to setup that up again.

Brilliant, thanks. That thread you linked to was one I’d looked through a few days ago but like many which talk about date based archives are just a little over my head at the moment. And I don’t know how many work with this latest version as well.

Thanks again

Offline

#15 2014-10-29 21:56:26

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [howto] Date-Based Archives - Yearly, Monthly, Daily, and Complete

I uploaded a new 1.1 version of the plugin to Github. This one works correctly if Textpattern is installed in a Subdirectory.

Offline

#16 2020-07-04 13:50:01

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#17 2020-07-04 14:41:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

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

#18 2020-07-06 13:46:44

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#19 2020-07-06 13:54:40

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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.

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" />" />
        &#183;
        <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

Board footer

Powered by FluxBB