Articles now.Years only on my blog


i wish filter my articles in my blog. i wish only articles of now years 2020.
i don"t found solution . i was thinking use {{ if eq .Date.Year now.Year }}
but i don’t know use this
my blog list use this code for working :slight_smile:

blog list

{{ define “main” }}

{{ range .Pages }}

<div class=" relative bg-white sm:w-full w-3/4 shadow-2xl rounded-lg overflow-hidden mx-auto">

    <!-- top image carte -->
        <img src="{{with .Params.featured_image}}{{.}}{{else}}{{ .Site.Params.featured_image }}{{end}}" alt=""
            class="object-fill w-full h-40">
    <div class=" m-2 text-justify text-sm ">

        <div class="flex flex-wrap items-center -mt-8 pb-3  ">
            <img class="block h-8 w-8 rounded-full bg-white mt-1 mr-2 ml-3 border-2 border-white "
                src='{{ range first 1 .Params.authors }}
                {{with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}{{ with }}{{ . }}{{ else }}{{ .Site.Params.authorimage }}{{ end }}{{ end }}{{ end }}'>
            {{ range .Params.authors }}
            {{with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}
            <a href='{{ .Permalink }}'><span
                    class="block text-lg  font-bold text-white">{{ with }}{{ . }}{{else}}{{ .Params.title }}{{end}}{{ end }}{{ end }}</span></a>

        <div class=" ">
            <p class=" text-right -mt-4 text-xs"> <i class=" mr-1 far fa-calendar-alt"></i>

                <!-- date en Fr via data/mois.yaml merci ;) -->
                <time class="post-date dt-published"
                    datetime='{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}'>{{ .Date.Day }}
                    {{ index $.Site.Data.mois (printf "%d" .Date.Month) }} {{ .Date.Year }}</time> </p>

            <p class=" text-right  text-xs"> <i class=" mr-1 fas fa-clock"></i>
                {{.ReadingTime }} minutes
            <h2 class=" font-bold mb-1 text-center"> <a href="{{ .Permalink }}">{{ .Title }}</a> </h2>

            <p class=" h-32 md:h-40 text-xs p-3"> {{ with .Params.description }}
                {{ . }}
                {{ else }}
                {{ .Summary }}
                {{ end }}


    <a href="{{ .Permalink }}">
        <div class=" absolute bottom-0 w-full py-2   text-center bg-blue-500 hover:bg-blue-900 text-white  ">

</div> {{ end }}

<div class=" relative text-center text-white  ">
    <a href="/archives/">
            class="fixed bottom-0 right-0  h-12 mx-auto pt-4 pb-4 rounded-tl-full align-middle w-24 bg-blue-500 hover:bg-blue-800 ">
            Archives </p>

{{ end }}

thanks my friends

If you replace…

{{ range .Pages }}


{{ range where .Pages "Date.Year" now.Year }}

Then you should get a list with all pages published this year. :slightly_smiling_face:

1 Like

Many thanks @Jura
it’s cool & easy :smiley: :kissing_closed_eyes:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.