5
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Movable Typeテンプレート処理まとめ

Posted at

#記事Newボタン表示処理(14日以内)

<$MTDate format="%Y%m%d%H%M%S" setvar="before_date"$>
<$MTSetVar name="before_date" op="-" value="14000000"$>
<mt:Entries lastn="999">
    <$MTEntryDate format="%Y%m%d%H%M%S" setvar="entry_date"$>
    <mt:If name="entry_date" gt="$before_date"$>
        <span class="txt-caution">NEW</span>
    </mt:If>
</mt:Entries>

#Paging処理(PageBute)

<MTPageContents count="10">
<mt:Entries lastn="999">
    <$MTPageSeparator$>
</mt:Entries>
</MTPageContents>

<MTPagination>
    <MTPaginationHeader>
    <div class="box-pager">
        <p class="box-pager__button box-pager__prev"><a href="<$MTPaginationPrev$>"><i class="icn icn-arrow-left03"></i>前のページ</a></p>
        <ul class="box-pager__page">
    </MTPaginationHeader>
        <MTIfPaginationCurrent>
            <li><a href="<$MTPaginationLink$>" class="is-current"><$MTPaginationLink element="number"$></a></li>
        <MTElse>
            <li><a href="<$MTPaginationLink$>"><$MTPaginationLink element="number"$></a></li>
        </MTIfPaginationCurrent>
    <MTPaginationFooter>
        </ul>
        <p class="box-pager__button box-pager__next"><a href="<$MTPaginationNext$>">次のページ<i class="icn icn-arrow-right05"></i></a></p>
    </div>
    </MTPaginationFooter>
</MTPagination>

#モジュール共通化

<mt:If name="main_index">
<mt:Ignore>=== TOP画面 ===</mt:Ignore>
<mt:ElseIf name="datebased_monthly_archive">
<mt:Ignore>=== 月別一覧 ===</mt:Ignore>
<mt:ElseIf name="datebased_daily_archive">
<mt:Ignore>=== 日別一覧 ===</mt:Ignore>
<mt:ElseIf name="category_archive">
<mt:Ignore>=== カテゴリ一覧 ===</mt:Ignore>
<mt:ElseIf name="search_results">
<mt:Ignore>=== 検索結果 ===</mt:Ignore>
<mt:ElseIf name="entry_archive">
<mt:Ignore>=== 記事詳細 ===</mt:Ignore>
</mt:If>

※参照リンク
https://www.movabletype.jp/documentation/designer/archive-template-variable.html

#年単位、月単位アーカイブ処理

<mt:ArchiveList type="Yearly" sort_order="descend">
    <mt:SetvarBlock name="archiveYear"><$mt:ArchiveDate format="%Y"$></mt:SetvarBlock>
    <mt:ArchiveList type="Monthly" sort_order="descend">
        <mt:SetvarBlock name="archiveYear"><$mt:ArchiveDate format="%Y"$></mt:SetvarBlock>
        <mt:SetvarBlock name="archiveMonth"><$mt:ArchiveDate format="%m" regex_replace="/^0/",""$></mt:SetvarBlock>
        <li><a href="<$mt:ArchiveLink$>"><$mt:Var name="archiveYear"$>年<$mt:Var name="archiveMonth"$>月</a></li>
    </mt:ArchiveList>
</mt:ArchiveList>

#記事ループ小技

<mt:Entries lastn="5" sort_order="descend">
<mt:If name='__first__'>I am first</mt:If>
</mt:Entries>

first ループ中で一番最初の記事にだけ出力
last ループ中で一番最後の記事にだけ出力
odd ループ中で奇数回目の記事にだけ出力
even ループ中で偶数回目の記事にだけ出力

#Replace処理

<$mt:Var name="value" regex_replace="/-H/","" setvar="value"$>

#For文処理カンマ区切りで処理

<$mt:SetVar name="favorite" value="バッジョ,ジーコ,クライフ,ピルロ,ストイコビッチ,グアルディオラ"$>
<$mt:Var name="favorite" regex_replace="/[^,]/g","" cat="," count_characters="1" setvar="length"$>
<mt:For var="i" from="1" to="$length">
  <mt:If name="__first__"><ul></mt:If>
  <$mt:Var name="favorite" regex_replace="/^([^,]+).*/","$1" setvar="value"$>
  <$mt:Var name="favorite" regex_replace="/^([^,]+,?)(.*)/","$2" setvar="favorite"$>
  <li><$mt:Var name="value"$></li>
  <mt:If name="__last__"></ul></mt:If>
</mt:For>

#計算処理

<mt:SetVar name="count" value="1"></mt:SetVar>
<mt:Entries lastn="20">
    <MTSetVar name="count" value="1" op="+">
</mt:Entries>

#カテゴリ一覧

<mt:TopLevelCategories sort_order="descend">
<mt:If tag="CategoryCount">
    <mt:SetVarBlock name="category_label2"><$MTCategoryLabel$></mt:SetVarBlock>
    <mt:If name="category_label2" eq="$category_label">
        <li><a href="<$mt:CategoryArchiveLink$>" class="current"><span><$mt:CategoryLabel$></span></a></li>
    <mt:else>
        <li><a href="<$mt:CategoryArchiveLink$>"><span><$mt:CategoryLabel$></span></a></li>
    </mt:else>
    </mt:If>
</mt:If>
</mt:TopLevelCategories>

<mt:IfArchiveTypeEnabled archive_type="Category">
<mt:if tag="BlogCategoryCount">
	<mt:TopLevelCategories sort_order="descend">    
		<mt:SetVarBlock name="category_label2"><$MTCategoryLabel$></mt:SetVarBlock>
            <mt:If name="category_label2" eq="$category_label">
            <mt:SubCategories>
            <mt:SubCatIsFirst>
                <ul>
                </mt:SubCatIsFirst>
                <mt:If tag="CategoryCount">
                    <mt:Entries>
                        <li><a href="<$mt:EntryPermalink encode_html="1"$>" target="_blank"><$mt:EntryTitle$></a></li>
                    </mt:Entries>
                </mt:If>
                <$mt:SubCatsRecurse$>
                <mt:SubCatIsLast>
                </ul>
            </mt:SubCatIsLast>
            </mt:SubCategories>
            </mt:If>
    </mt:TopLevelCategories>
</mt:if>
</mt:IfArchiveTypeEnabled>
5
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?