Text3. Explain about Label2

テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明

テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明

テキスト3 ラベル2の説明
テキスト3 ラベル2の説明
テキスト3 ラベル2の説明

テキスト3 ラベル2の説明 テキスト3 ラベル2の説明 テキスト3 ラベル2の説明
テキスト3 ラベル2の説明

テキスト3 ラベル2の説明 テキスト3 ラベル2の説明

2011-05-15

特定のラベルを表示したときだけ投稿記事の上にテキストのウィジェットを表示させたい!

トップページ - TEXT 1 Widget
<b:if cond='data:blog.url == data:blog.homepageUrl'>...</b:if>
ラベル1 - TEXT 2 Widget
<b:if cond='data:blog.url == "LABEL 1 URL"'>...</b:if>
ラベル2 - TEXT 3 Widget 
<b:if cond='data:blog.url == "LABEL 2 URL"'>...</b:if>


トップページのTEXT1は
<b:if cond='data:blog.pageType == "index"'>だと機能しなかったので、
<b:if cond='data:blog.url == data:blog.homepageUrl'>


但し、この「ラベルが選択されたら」という条件は、表示された最初の1ページ目だけに有効です。
2ページ目以降(1ページには20件(要検討))は URL が変わってしまうために条件に一致しなくなります。





参考
How can I show a specific text widget, when a specific label is opened?
http://www.google.com/support/forum/p/blogger/thread?fid=2d5e0604c0846ca70004a33f51d0254c&hl=en



Use label URL, like this:
<b:if cond='data:blog.url == "PUT LABEL URL HERE"'>

an example,
<b:if cond='data:blog.url == "http://sample64sample.blogspot.com/search/label/Kustom%20Records"'>
References:




I. Conditional tag syntax

The syntax is like this:
1<b:if cond='PUT_CONDITION_HERE'>
2</b:if>
It is made up of a <b:if> tag, with a  cond attribute added. Condition is entered as the value of the cond attribute. Each (opening) <b:if> tag need to be closed with a closing </b:if> tag.

II. List of conditional tags

Below is a list of conditional tags that target specific pages. I only list the opening tags here. Just make sure you include the closing </b:if> tag when applying a conditional in your template.
  1. Index (list) pages 
    Index pages include homepage, labels page and yearly archive page. 
    1<b:if cond='data:blog.pageType == "index"'>
  2. Post (item) page 
    1<b:if cond='data:blog.pageType == "item"'>
  3. Static Page 
    1<b:if cond='data:blog.pageType == "static_page"'>
  4. Archive page 
    1<b:if cond='data:blog.pageType == "archive"'>
  5. Homepage 
    1<b:if cond='data:blog.url == data:blog.homepageUrl'>
  6. Specific page/url 
    1<b:if cond='data:blog.url == "PUT_URL_HERE"'>

III. Applying conditional tags

  • To apply a conditional tag to a content, simply put the content between the opening <b:if cond…> and the closing </b:if>, like so: 
    1<b:if cond='data:blog.pageType == "item"'>
    2CONTENT (TO BE EXECUTED IF CONDITION IS TRUE)
    3</b:if>
    In the example above, the content will only appear on post pages.
  • If you want to specify a alternate content (when the condition is false), you need to insert a <b:else/> tag followed by the content, like this: 
    1<b:if cond='data:blog.pageType == "item"'>
    2CONTENT 1 (TO BE EXECUTED IF CONDITION IS TRUE)
    3<b:else/>
    4CONTENT 2 (TO BE EXECUTED IF CONDITION IS FALSE)
    5</b:if>
    You can place the conditional anywhere in your template HTML, except inside a section or inside a widget content box. The content can be a div, a section, a style tag, another conditional tag etc.
  • Reversing a condition 
    A condition can be reversed simply by replacing the comparison operator from== (is equal to) to != (is not equal to), like so:
    1<b:if cond='data:blog.pageType != "item"'>
    2CONTENT (TO BE EXECUTED IF CONDITION IS TRUE)
    3</b:if>
    In the example above, the content will only appear on pages other than post pages (i.e. removed/hidden from post pages).

IV. Application examples

Below are some examples of what you can do with conditional tags:



参考 2
トップページにだけ表示したい。
http://www.google.com/support/forum/p/blogger/thread?tid=4892e22dee25eedc&hl=ja
レイアウトテンプレートのウィジェットタグ b:if や b:else を使うと、
閲覧ページに合わせて、ガジェット(ウィジェット)内の表示内容を変えることができます。

このタグについてはこちらを確認してください。

・レイアウト用ウィジット タグ - Blogger ヘルプ
http://www.google.com/support/blogger/bin/answer.py?hl=ja&answer=46995

ページの種類を表すデータは <data:pageType/> というデータタグで参照することができます。
ヘルプによると、この <data:pageType/> の内容は 'item'(投稿単独ページ)、'archive'(アーカイブページ)、'index'(トップページ)のいずれかだということです。
データタグについてはこちらを確認してください。

・レイアウト データ タグ - Blogger ヘルプ
http://www.google.com/support/blogger/bin/answer.py?hl=ja&answer=47270

これらを組み合わせて

<b:if cond='data:blog.pageType == "index"'>
  (トップページに表示させたいガジェットの内容)
</b:if>

と書くと、トップページにのみ、そのガジェットが表示されることになります。
具体的には、「レイアウト > HTML の編集」から「ウィジェットのテンプレートを展開」というチェックボックスにチェックを入れ、
該当のガジェットのコードをみつけます。
Blogger のガジェットのコードは

<b:widget ... >
<b:includable id='main'>
...
</b:includable>
...(main 以外の includable タグ)
</b:widget>

という構造になっているので、main の includable の開始タグ・終了タグのすぐ内側に b:if の開始タグ、終了タグを挿入して

<b:widget ... >
<b:includable id='main'>
<b:if cond='data:blog.pageType == "index"'>
...
</b:if>
</b:includable>
...(main 以外の includable タグ)
</b:widget>

のようにするといいと思います。



参考3
ifによるラベルの条件分岐

> そこで、以下のようにやると あああ というラベルの記事のみ日付の非表示ができるようになったのですが、

質問でお示しのテンプレートタグは、それぞれの投稿に対して付加されている全ラベルを検査し、「あああ」の場合何もせず、「あああ」以外のラベルの場合日付を表示する…というようになっていると思いますが、これだと以下のように色々と変な振る舞いをしてしまうと思います

・ラベルなしだと日付を表示できない。
・「あああ」ラベルがあっても、他のラベルがあれば日付が表示されてしまう。
・「あああ」以外のラベルが複数あれば、その数だけ同じ日付が連続して表示されてしまう。

それで、私ならこうするかな?…というのを載せておきます。また

> たとえば、 あああ もしくは いいい という2つのラベルを非表示にしたい場合、どのような記述の仕方をすればよいか分からず・・・

についても、解決してみたつもりです。参考にしていただけたら嬉しいです。

<b:loop values='data:post.labels' var='label'>
  <b:if cond='data:label.name == &quot;nodate1&quot;'>
    <style type='text/css'>#date-header-<data:post.id/> {display: none;}</style>
  <b:else/>
    <b:if cond='data:label.name == &quot;nodate2&quot;'>
      <style type='text/css'>#date-header-<data:post.id/> {display: none;}</style>
    </b:if>
  </b:if>
</b:loop>
<b:if cond='data:post.dateHeader'>
  <h2 class='date-header' expr:id='&quot;date-header-&quot; + data:post.id'><data:post.dateHeader/></h2>
</b:if>

ブログ アーカイブ