【发布时间】:2016-01-08 14:33:19
【问题描述】:
我试图根据用户访问的页面显示不同的标题图像。下面的代码很好用,除了 is_archive(listings)
出于某种原因,它想使用来自 is_archive(team) 的图像
<div class="header-images">
<?php if (is_archive('team')) { ?>
<img src="<?php the_field('header_image_team', 'options'); ?>" class="img-responsive bkg" />
<?php } elseif (is_singular('team')) { ?>
<img src="<?php the_field('header_image_team', 'options') ?>" class="img-responsive bkg" />
<?php } elseif (is_archive('listings')) { ?>
<img src="<?php the_field('header_image_listings', 'options'); ?>" class="img-responsive bkg" />
<?php } elseif (is_singular('listings')) { ?>
<img src="<?php the_field('header_image_single') ?>" class="img-responsive bkg" />
<?php } elseif (is_home()) { ?>
<img src="<?php the_field('header_image_ic', 'options') ?>" class="img-responsive bkg" />
<?php } ?>
对于它的价值,我将它与 Advanced Custom Fields PRO 一起使用。所以我为自定义帖子类型设置了一个选项页面:团队和列表。在每个帖子类型菜单中都有一个设置面板,可以上传图片。
单数“列表”从每个帖子中提取一张图片,然后当然 is_home(默认博客)有一个选项面板,其中包含要上传的图片。
总的来说,如果我没有声明“列表”的存档页面应该显示团队形象,那么它不应该显示任何东西,对吧?
这是 ACF Pro 选项的功能。
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Header Settings',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Footer Settings',
'menu_title' => 'Footer',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'title' => 'Team Settings',
'parent' => 'edit.php?post_type=team',
'capability' => 'manage_options'
));
acf_add_options_sub_page(array(
'title' => 'Listings Settings',
'parent' => 'edit.php?post_type=listings',
'capability' => 'manage_options'
));
acf_add_options_sub_page(array(
'title' => 'Industry Coverage Settings',
'parent' => 'edit.php',
'capability' => 'manage_options'
));
}
【问题讨论】:
标签: wordpress if-statement advanced-custom-fields