Render single title with number prefix to every title of the blog

Hi everyone,

Last time I asked about how I can add a prefix of numbers to my blog for each position of the blog post. The solution worked really well. Here is the discussion for context

I this code works really well for the index homepage. I have tried to use it for a single blog post but it has instead listed all titles instead of just listing only one tile along with its unique prefix (0000, 0003, 0005 for example are the unique prefixes).

Below is what it looks like for a single title. In it for example the only title I want rendered (along with its prefix) is “0000 Why bockchains are not mainstream”. But it instead renders titles for all blog posts.

Is there a way I can have only a single title for each respective blogpost along with its prefix?

Below is the current cod that I am working with;

      {{ $list_of_posts := (where .Site.RegularPages  "Section" "posts" ).ByDate.Reverse }}
      {{ $counter := sub (len (where .Site.RegularPages "Section" "=" "posts")) 1 }}
      {{ $current_post := 6}}

      {{ range $list_of_posts }}

        {{ if compare.Le $counter 9 }}
        <h2 itemprop="name headline"><span style="color: #ecdbba;">000{{ $counter }}</span> {{ .Title }}</h2>
        {{ end}}

        {{ if and (compare.Le $counter 99)  (compare.Gt $counter 9) }}
        <h2 itemprop="name headline"><span style="color: #ecdbba;">00{{ $counter }}</span> {{ .Title }}</h2>
        {{ end}}

        {{ if and (compare.Le $counter 999)  (compare.Gt $counter 99) }}
        <h2 itemprop="name headline"><span style="color: #ecdbba;">0{{ $counter }}</span> {{ .Title }}</h2>
        {{ end}}

        {{ $counter = sub $counter 1  }}

      {{ end }}

Thanks in advance.

I finaly solved it thsi morning.

Below is the code that worked for any one that may have the same interest.

      {{ $list_of_posts := (where .Site.RegularPages  "Section" "posts" ).ByDate.Reverse }}
      {{ $counter := sub (len (where .Site.RegularPages "Section" "=" "posts")) 1 }}
      {{ $current_post := .Title }}

      {{ range $list_of_posts }}

        {{ if compare.Le $counter 9 }}
          {{ if compare.Eq $current_post .Title}}
          <h2 itemprop="name headline"><span style="color: #ecdbba;">000{{ $counter }}</span> {{ $current_post }}</h2>
          {{ break }}
        {{ end }}
        {{ end}}

        {{ if and (compare.Le $counter 99)  (compare.Gt $counter 9) }}
        <h2 itemprop="name headline"><span style="color: #ecdbba;">00{{ $counter }}</span> {{ .Title }}</h2>
        {{ end}}

        {{ if and (compare.Le $counter 999)  (compare.Gt $counter 99) }}
        <h2 itemprop="name headline"><span style="color: #ecdbba;">0{{ $counter }}</span> {{ .Title }}</h2>
        {{ end}}

        {{ $counter = sub $counter 1  }}

      {{ end }}

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