PowerCMS™
[ブログ] PowerCMS 6 でのアップデートまとめ を追加しました。
[ブログ] 人事・教育担当より アルファサードのメンバーに求めていること を追加しました。
[ブログ] PowerCMS サポートの実績 (2024年2月) を追加しました。
[よくあるご質問] スケジュールタスクが実行されているか確認する方法はありますか? を追加しました。

PowerCMS ブログ

ホーム > PowerCMS ブログ > その他 > テンプレートを使ってCMSに登録されたコンテンツの一覧を出力する

2017年02月03日

テンプレートを使ってCMSに登録されたコンテンツの一覧を出力する

既存のPowerCMSやMovable Typeで構築されたサイトのコンテンツの量を把握するには管理画面のウェブサイト一覧や記事の一覧などを確認しますが、出力URL等を含んだ状態でコンテンツの一覧をExcel等へ落とし込むことは若干難しいです。

今回はテンプレートを利用してコンテンツの一覧を出力する方法を説明します。

手順

任意のウェブサイト・ブログの管理画面のメニュー「デザイン」→「テンプレート」でテンプレート一覧へ遷移し、「インデックステンプレートの作成」からインデックステンプレートの作成画面へ移動します。

テンプレート名と出力ファイル名(拡張子はhtml)を適当に設定します。

テンプレートに以下をコピーします。

<MTSetVarTemplate name="get_categories">
    <MTSubCategories top="1">
        <tr>
            <td>カテゴリ</td>
            <td><$MTCategoryID$></td>
            <td><$MTWebsiteName encode_html="1"$></td>
            <td><MTIfBlog><$MTBlogName encode_html="1"$><MTElse>-</MTElse></MTIfBlog></td>
            <td><$MTCategoryLabel encode_html="1"$></td>
            <td><$MTCategoryCount$></td>
            <td>-</td>
            <td><a href="<$MTCategoryArchiveLink$>" target="_blank"><$MTCategoryArchiveLink$></a></td>
            <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=view&amp;_type=category&amp;blog_id=<$MTBlogID$>&amp;id=<$MTCategoryID$>" target="_blank">編集</a></td>
        </tr>
        <$MTSubCatsRecurse$>
    </MTSubCategories>
</MTSetVarTemplate>

<MTSetVarTemplate name="get_folders">
    <MTSubFolders top="1">
        <tr>
            <td>フォルダ</td>
            <td><$MTFolderID$></td>
            <td><$MTWebsiteName encode_html="1"$></td>
            <td><MTIfBlog><$MTBlogName encode_html="1"$><MTElse>-</MTElse></MTIfBlog></td>
            <td><$MTFolderLabel encode_html="1"$></td>
            <td>-</td>
            <td><$MTFolderCount$></td>
            <td><$MTFolderPath$></td>
            <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=view&amp;_type=folder&amp;blog_id=<$MTBlogID$>&amp;id=<$MTCategoryID$>" target="_blank">編集</a></td>
        </tr>
        <$MTSubCatsRecurse$>
    </MTSubFolders>
</MTSetVarTemplate>

<MTSetVarTemplate name="get_entries">
    <MTEntries lastn="0">
        <tr>
            <td>記事</td>
            <td><$MTEntryID$></td>
            <td><$MTWebsiteName encode_html="1"$></td>
            <td><MTIfBlog><$MTBlogName encode_html="1"$><MTElse>-</MTElse></MTIfBlog></td>
            <td><MTEntryCategories glue=","><$MTCategoryLabel encode_html="1"$></MTEntryCategories></td>
            <td><$MTEntryTitle encode_html="1"$></td>
            <td><a href="<$MTEntryPermalink$>" target="_blank"><$MTEntryPermalink$></a></td>
            <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=view&amp;_type=entry&amp;blog_id=<$MTBlogID$>&amp;id=<$MTEntryID$>" target="_blank">編集</a></td>
        </tr>
    </MTEntries>
</MTSetVarTemplate>

<MTSetVarTemplate name="get_pages">
    <MTPages lastn="0">
        <tr>
            <td>ページ</td>
            <td><$MTPageID$></td>
            <td><$MTWebsiteName encode_html="1"$></td>
            <td><MTIfBlog><$MTBlogName encode_html="1"$><MTElse>-</MTElse></MTIfBlog></td>
            <td><MTPageFolder><$MTFolderLabel encode_html="1"$></MTPageFolder></td>
            <td><$MTPageTitle encode_html="1"$></td>
            <td><a href="<$MTPagePermalink$>" target="_blank"><$MTPagePermalink$></a></td>
            <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=view&amp;_type=page&amp;blog_id=<$MTBlogID$>&amp;id=<$MTEntryID$>" target="_blank">編集</a></td>
        </tr>
    </MTPages>
</MTSetVarTemplate>

<MTFor regex_replace="/^\s*/gm","">
<!DOCTYPE html><html>
    <head><meta charset="UTF-8">
        <style>
            body {font-size:80%;padding:10px;margin:0px}
            table {font-size:1em;border-collapse:collapse;border-spacing:0;margin:0 0 1em}
            td, th {font-weight:400;border:1px solid #666;text-align:left;padding:.3em .5em;vertical-align:top}
            th {background-color:#efefef}
            caption {caption-side:top;text-align:left;padding: 0 0 0.5em;font-weight:bold}
        </style>
    </head>
    <body>
        <table>
            <caption>ウェブサイト・ブログ</caption>
            <thead>
            <tr>
                <th>種類</th>
                <th>ID</th>
                <th>ウェブサイト名</th>
                <th>ブログ名</th>
                <th>記事数</th>
                <th>ページ数</th>
                <th>URL</th>
                <th>編集</th>
            </tr>
            </thead>
            <tbody>
            <MTWebsites include_websites="all">
            <tr>
                <td>ウェブサイト</td>
                <td><$MTWebsiteID$></td>
                <td><$MTWebsiteName encode_html="1"$></td>
                <td>-</td>
                <td><$MTWebsiteEntryCount$></td>
                <td><$MTWebsitePageCount$></td>
                <td><a href="<$MTWebsiteURL$>" target="_blank"><$MTWebsiteURL$></a></td>
                <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=cfg_prefs&amp;blog_id=<$MTBlogID$>" target="_blank">編集</a></td>
            </tr>
            <MTBlogs include_blogs="children">
            <tr>
                <td>ブログ</td>
                <td><$MTBlogID$></td>
                <td><$MTWebsiteName encode_html="1"$></td>
                <td><$MTBlogName encode_html="1"$></td>
                <td><$MTBlogEntryCount$></td>
                <td><$MTBlogPageCount$></td>
                <td><a href="<$MTBlogURL$>" target="_blank"><$MTBlogURL$></a></td>
                <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=cfg_prefs&amp;blog_id=<$MTBlogID$>" target="_blank">編集</a></td>
            </tr>
            </MTBlogs>
            </MTWebsites>
            </tbody>
        </table>
        
        <table>
            <caption>カテゴリ・フォルダ</caption>
            <thead>
            <tr>
                <th>種類</th>
                <th>ID</th>
                <th>ウェブサイト名</th>
                <th>ブログ名</th>
                <th>カテゴリ・フォルダ名</th>
                <th>記事数</th>
                <th>ページ数</th>
                <th>URL</th>
                <th>編集</th>
            </tr>
            </thead>
            <tbody>
            <MTWebsites include_websites="all">
                <$MTGetVar name="get_categories"$>
                <$MTGetVar name="get_folders"$>
                <MTBlogs include_blogs="children">
                    <$MTGetVar name="get_categories"$>
                    <$MTGetVar name="get_folders"$>
                </MTBlogs>
            </MTWebsites>
            </tbody>
        </table>
        
        <table>
            <caption>記事・ページ</caption>
            <thead>
            <tr>
                <th>種類</th>
                <th>ID</th>
                <th>ウェブサイト名</th>
                <th>ブログ名</th>
                <th>カテゴリ・フォルダ名</th>
                <th>記事・ページ名</th>
                <th>URL</th>
                <th>編集</th>
            </tr>
            </thead>
            <tbody>
            <MTWebsites include_websites="all">
                <$MTGetVar name="get_entries"$>
                <$MTGetVar name="get_pages"$>
                <MTBlogs include_blogs="children">
                    <$MTGetVar name="get_entries"$>
                    <$MTGetVar name="get_pages"$>
                </MTBlogs>
            </MTWebsites>
            </tbody>
        </table>
    </body>
</html>
</MTFor>

(入力画面)
入力画面の拡大表示

「プレビュー」ボタンを押すことで、上記のテンプレートを元に

  • ウェブサイト・ブログの一覧
  • カテゴリ・フォルダの一覧
  • 記事・ページの一覧

が出力されます。

(出力サンプル)
出力画面の拡大表示

カスタム項目(カスタムオブジェクト)の出力

同じ要領でPowerCMSのカスタム項目(カスタムオブジェクト)の一覧も出力することができます。

<MTSetVarTemplate name="get_customobjects">
    <MTCustomObjects lastn="0">
        <tr>
            <td>カスタム項目</td>
            <td><$MTCustomObjectID$></td>
            <td><$MTWebsiteName encode_html="1"$></td>
            <td><MTIfBlog><$MTBlogName encode_html="1"$><MTElse>-</MTElse></MTIfBlog></td>
            <td><MTCustomObjectFolder><$MTFolderLabel encode_html="1"$></MTCustomObjectFolder></td>
            <td><$MTCustomObjectName encode_html="1"$></td>
            <td><MTIf tag="MTCustomObjectPermalink"><a href="<$MTCustomObjectPermalink$>" target="_blank"><$MTCustomObjectPermalink$></a><MTElse><$MTCustomObjectBasename$></MTElse></MTIf></td>
            <td><a href="<$MTAdminCGIPath$><$MTAdminScript$>?__mode=view&amp;_type=customobject&amp;blog_id=<$MTBlogID$>&amp;id=<$MTCustomObjectID$>" target="_blank">編集</a></td>
        </tr>
    </MTCustomObjects>
</MTSetVarTemplate>

<table>
    <caption>カスタム項目</caption>
    <thead>
    <tr>
        <th>種類</th>
        <th>ID</th>
        <th>ウェブサイト名</th>
        <th>ブログ名</th>
        <th>カテゴリ・フォルダ名</th>
        <th>記事・ページ名</th>
        <th>URL・ベースネーム</th>
        <th>編集</th>
    </tr>
    </thead>
    <tbody>
    <MTWebsites include_websites="all">
        <$MTGetVar name="get_customobjects"$>
        <MTBlogs include_blogs="children">
            <$MTGetVar name="get_customobjects"$>
        </MTBlogs>
    </MTWebsites>
    </tbody>
</table>

上記はPowerCMSでデフォルトで用意されているカスタムオブジェクトの一覧を出力するための記述です。
後から追加したカスタムオブジェクトを出力する場合は適宜テンプレートタグを修正します。

注意点

一覧で出力される記事やウェブページ、カスタムオブジェクトはステータスが「公開」のものだけ出力されます。「未公開」のものは表示されません。


カテゴリー
その他
投稿者
Fujimoto

Recent Entries