<?php // SEARCH TAGS FOR A SPECIFIC TAG
$tags = CollectionAttributeKey::getByHandle('recipe_tags'); // attribute handle of tags to search
$tagToFind = 'Videos'; // declare the specific tag to find
$selectedTags = array($page->getAttribute($tags->getAttributeKeyHandle())); // get tags associated with each page and put them in an array
foreach ($selectedTags as $tag) { // output tags separately
echo $tag; // ECHO TEST - check that individual tags associated with each page are outputting correctly
if ($tag == $tagToFind) { // if $tag is equal to $tagToFind
echo ' Found';
} else {
echo ' Not found';
}
}
?>
echo $tag;
各ページに関連付けられたタグのリストを出力するので、「ビデオ」がタグのリストにあるかどうかを確認する方法に問題があると確信しています。
上記は次のリストを出力します:Breakfast
Brunch
Budget
Meal
Easy
Lunch
Quick Meals
Supper
Vegetarian
Videos
そしてNot found
Videos がリストにあるにもかかわらず。
また、次のように in_array を使用して「ビデオ」を探してみました。
if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict
echo ' Found';
} else {
echo ' Not found';
}
しかし、同じ結果が得られます-私はphpが初めてなので、これが簡単であれば申し訳ありません。
どんな助けでも大歓迎です。
乾杯