2
Я пытаюсь показать 3 случайные категории в своих сообщениях.Wordpress - If Statement in variable
Я использую плагин Advanced Custom Fieds, чтобы показать изображение категории. Если утверждение:
if (get_field('portada', 'category_' . $cats->term_id)) {
echo '<a class="cover margin-ultimos" href="' . get_category_link($cats->term_id) . '">';
echo '<div id="cover-home" class="gray-shadow">';
echo '<img src="'. get_field('portada', 'category_'.$cats->term_id). '" alt="Portada'. get_cat_name ($cats->term_id) . '" />';
echo '</div>';
И я пытаюсь показать это с помощью wp_list_categories, поэтому я добавил в functions.php файла эти строки:
add_filter ('wp_list_categories', 'img_before_link_list_categories');
function img_before_link_list_categories($list) {
$cats = get_categories();
foreach($cats as $cat) {
$find = $cat->name.'</a>';
$replace = '//Here the If Statement to show the image';
$list = str_replace($find, $replace, $list);
$list = preg_replace('%<li class=".*">|</?ul>%U', '<h2>', $list);
$list = str_replace('</li>', '</h2>', $list);
}
return $list;
}
Как можно сохранить, если заявление в $replace
переменная?
Thats work. Благодаря! – Ferrrmolina
Просто отсутствует '' в последнем '$ replace. = ... 'и, thats work correclty :) – Ferrrmolina
Тонкая настройка по мере необходимости. Рад слышать это! –