37 commonly used Halo Java lightweight blog page template tag calls (quick call page data)

This article should be regarded as the last article on the development of Halo Java lightweight blog program. In front, Lao Jiang sorted out the calls to Halo pages, public templates and global variables. Here, do we need to call page template labels, such as the latest articles, menus and picture groups? This article is a relatively complete collection of 37 Halo page template labels.

Template tags can be used anywhere on the page.

First, article (postTag)

1. Get latest articles

<@postTag method="latest" top="3">
    <#list posts as post>
        <a href="${post.fullPath!}">${post.title!}</a>
    </#list>
</@postTag>

2. Get the number of all articles (count)

<@postTag method="count">
<span>Number of articles: ${count!0}</span>
</@postTag>

3. Archive year

<@postTag method="archiveYear">
  <#list archives as archive>
      <h1>particular year: ${archive.year?c}</h1>
      <ul>
          <#list archive.posts?sort_by("createTime")?reverse as post>
            <li>
              <a href="${post.fullPath!}">${post.title!}</a>
            </li>
          </#list>
      </ul>
  </#list>
</@postTag>

4. Archive according to the month and year (archiveMonth)

<@postTag method="archiveMonth">
  <#list archives as archive>
      <h1>${archive.year?c}-${archive.month?c}</h1>
      <ul>
          <#list archive.posts?sort_by("createTime")?reverse as post>
            <li>
              <a href="${post.fullPath!}">${post.title!}</a>
            </li>
          </#list>
      </ul>
  </#list>
</@postTag>

5. archive

<@postTag method="archive" type="month">
  <#list archives as archive>
      <h1>${archive.year?c}-${archive.month?c}</h1>
      <ul>
          <#list archive.posts?sort_by("createTime")?reverse as post>
            <li>
              <a href="${post.fullPath!}">${post.title!}</a>
            </li>
          </#list>
      </ul>
  </#list>
</@postTag>

6. Get articles by category id (listByCategoryId)

<@postTag method="listByCategoryId" top="${category.id?c}">
    <span>classification ${category.name!} The following article:</span>
    <#list posts as post>
        <a href="${post.fullPath!}">${post.title!}</a>
    </#list>
</@postTag>

7. Get articles by category slug (listByCategorySlug)

<@postTag method="listByCategorySlug" categorySlug="${category.slug!}">
    <span>classification ${category.name!} The following article:</span>
    <#list posts as post>
        <a href="${post.fullPath!}">${post.title!}</a>
    </#list>
</@postTag>

8. Get article by tag id (listByTagId)

<@postTag method="listByTagId" tagId="${tag.id?c}">
    <span>label ${tag.name!} The following article:</span>
    <#list posts as post>
        <a href="${post.fullPath!}">${post.title!}</a>
    </#list>
</@postTag>

9. Get articles according to tag slug (listByTagSlug)

<@postTag method="listByTagSlug" tagSlug="${tag.slug!}">
    <span>label ${tag.name!} The following article:</span>
    <#list posts as post>
        <a href="${post.fullPath!}">${post.title!}</a>
    </#list>
</@postTag>

Second, comment tag

1. Get latest comments

<@commentTag method="latest" top="Get number of entries">
    <ul>
        <#list comments.content as comment>
            <li>${comment.author!}: ${comment.content!}</li>
        </#list>
    </ul>
</@commentTag>

2. Get the number of all comments (count)

<@commentTag method="count">
<span>Number of comments: ${count!0}</span>
</@commentTag>

Third, category tag

1. Get all categories (list)

<@categoryTag method="list">
  <#list categories as category>
    <a href="${category.fullPath!}">${category.name!}(${category.postCount!})</a>
  </#list>
</@categoryTag>

2. Get all categories of articles (listByPostId)

<@categoryTag method="listByPostId" postId="${post.id?c}">
  <#list categories as category>
    <a href="${category.fullPath!}">${category.name}</a>
  </#list>
</@categoryTag>

3. Get the quantity of all classifications (count)

<@categoryTag method="count">
<span>Classification quantity: ${count!0}</span>
</@categoryTag>

Fourth, tagTag

1. Get all tags (list)

<@tagTag method="list">
  <#list tags as tag>
    <a href="${tag.fullPath!}">${tag.name!}(${tag.postCount!})</a>
  </#list>
</@tagTag>

2. Get all tags of the article (listByPostId)

<@tagTag method="listByPostId" postId="${post.id?c}">
  <#list tags as tag>
    <a href="${tag.fullPath!}">${tag.name}</a>
  </#list>
</@tagTag>

3. Get the number of all tags (count)

<@tagTag method="count">
<span>Number of labels: ${count!0}</span>
</@tagTag>

Fifth, menu (menuTag)

1. Get all menus (list)

<@menuTag method="list">
  <ul>
    <#list menus as menu>
      <li>
        <a href="${menu.url!}" target="${menu.target!}">${menu.name!}</a>
      </li>
    </#list>
  </ul>
</@menuTag>

2. Get multi-level menu (tree)

<@menuTag method="tree">
  <ul>
    <#list menus as menu>
      <li>
        <a href="${menu.url!}" target="${menu.target!}">${menu.name!}</a>
        <#if menu.children?? && menu.children?size gt 0>
            <ul>
              <#list menu.children as child>
                <li>
                  <a href="${child.url!}" target="${menu.target!}">${child.name!}</a>
                </li>
              </#list>
            </ul>
        </#if>
      </li>
    </#list>
  </ul>
</@menuTag>

3. Get menu by group (listByTeam)

<@menuTag method="listByTeam" team="main">
  <ul>
    <#list menus as menu>
      <li>
        <a href="${menu.url!}" target="${menu.target!}">${menu.name!}</a>
      </li>
    </#list>
  </ul>
</@menuTag>

4. Get multi-level menu according to group (treeByTeam)

<@menuTag method="treeByTeam" team="main">
  <ul>
    <#list menus as menu>
      <li>
        <a href="${menu.url!}" target="${menu.target!}">${menu.name!}</a>
        <#if menu.children?? && menu.children?size gt 0>
            <ul>
              <#list menu.children as child>
                <li>
                  <a href="${child.url!}" target="${menu.target!}">${child.name!}</a>
                </li>
              </#list>
            </ul>
        </#if>
      </li>
    </#list>
  </ul>
</@menuTag>

Sixth, links (linkTag)

1. Get all links (list)

<ul>
  <@linkTag method="list">
    <#list links as link>
        <li>
            <a href="${link.url!}" target="_blank">
                ${link.name!}
            </a>
        </li>
    </#list>
  </@linkTag>
</ul>

2. Get all links in random order (listByRandom)

<ul>
  <@linkTag method="list">
    <#list links as link>
        <li>
            <a href="${link.url!}" target="_blank">
                ${link.name!}
            </a>
        </li>
    </#list>
  </@linkTag>
</ul>

3. Get group links (listTeams)

<@linkTag method="listTeams">
  <#list teams as team>
    <h1>${team.team}</h1>
    <ul>
      <#list links as link>
        <li>
          <a href="${link.url!}" target="_blank">
          ${link.name!}
          </a>
        </li>
      </#list>
    </ul>
  </#list>
</@linkTag>

4. Get grouped links in random order (listTeamsByRandom)

<@linkTag method="listTeamsByRandom">
  <#list teams as team>
    <h1>${team.team}</h1>
    <ul>
      <#list links as link>
        <li>
          <a href="${link.url!}" target="_blank">
          ${link.name!}
          </a>
        </li>
      </#list>
    </ul>
  </#list>
</@linkTag>

5. Get the number of all links (count)

<@linkTag method="count">
<span>Number of links: ${count!0}</span>
</@linkTag>

Seventh, photo tag

1. Get all pictures (list)

<@photoTag method="list">
    <#list photos as photo>
        <img alt="${photo.description}" src="${photo.url}"/>
    </#list>
</@photoTag>

2. Get all grouped pictures (listTeams)

<@photoTag method="listTeams">
    <#list teams as team>
        <h1>${team.team}</h1>
    <#list team.photos as photo>
        <img alt="${photo.description}" src="${photo.url}"/>
    </#list>
    </#list>
</@photoTag>

3. Get pictures by group (listByTeam)

<@photoTag method="listTeams" team="scenery">
  <#list team.photos as photo>
    <img alt="${photo.description}" src="${photo.url}"/>
  </#list>
</@photoTag>

4. Get the number of all pictures (count)

<@linkTag method="count">
<span>Number of pictures: ${count!0}</span>
</@linkTag>

Eighth, paginationTag

1. Get the paging data of the home page article list (index)

<ul class="pagination">
    <@paginationTag method="index" page="${posts.number}" total="${posts.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

2. Get the paging data (archives) of the article archive list

<ul class="pagination">
    <@paginationTag method="archives" page="${posts.number}" total="${posts.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

3. Get paging data of search result article list (search)

<ul class="pagination">
    <@paginationTag method="search" page="${posts.number}" total="${posts.totalPages}" keyword="${keyword}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

4. Get the paging data of the article list under the tag (tagPosts)

<ul class="pagination">
    <@paginationTag method="tagPosts" slug="${tag.slug!}" page="${posts.number}" total="${posts.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

5. Get the paging data of the article list under the category (category posts)

<ul class="pagination">
    <@paginationTag method="categoryPosts" slug="${category.slug!}" page="${posts.number}" total="${posts.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

6. Get paging data (photos) of gallery page picture list

<ul class="pagination">
    <@paginationTag method="photos" page="${photos.number}" total="${photos.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

7. Get the paging data of the log page log list (journals)

<ul class="pagination">
    <@paginationTag method="journals" page="${journals.number}" total="${journals.totalPages}" display="3">
        <#if pagination.hasPrev>
            <li>
                <a href="${pagination.prevPageFullPath!}">previous page</a>
            </li>
        </#if>
        <#list pagination.rainbowPages as number>
            <#if number.isCurrent>
                <li>
                    <span class="current">${number.page!}</span>
                </li>
            <#else>
                <li>
                    <a href="${number.fullPath!}">${number.page!}</a>
                </li>
            </#if>
        </#list>
        <#if pagination.hasNext>
            <li>
                <a href="${pagination.nextPageFullPath!}">next page</a>
            </li>
        </#if>
    </@paginationTag>
</ul>

In this way, we can basically complete the calls required for Halo theme development by combining the page call tags, public templates, functions, etc. developed by other Halo themes.

Related articles:

1,Halo blog theme development page variable call demonstration sorting

2,Code specification of public macro template for Halo blog theme template development

3,Global variable template label calling and sorting of Halo blog theme development

Source: Laojiang tribe ยป 37 commonly used Halo Java lightweight blog page template tag calls (quick call page data)

Added by Yari on Thu, 23 Dec 2021 02:50:27 +0200