我有这个代码在标题中输出不同的代码片段,具体取决于我使用的页面模板。但我不能为我的生活让它发挥作用。
我基本上想要输出:
<div class="background-image" style="background-image: url('<?php echo $image[0]; ?>')"> </div>
如果有人正在查看网页模板header-hero.php
。
每当我这样做时,我都会在页面上看到这个输出:
Parse error: syntax error, unexpected 'is_page_template' (T_STRING), expecting '(' in /Users/Marc/Documents/Websites/www.psy-chosexualsomatics.dev/wp-content/themes/html5blank-stable/header.php on line 33
<header class="header clear" role="banner">
<?php function check_template() {if is_page_template( 'header-hero.php' ) {
if ( ! is_page() ) {
echo "<div class='background-image' style='background-image: url('" . $image[0]; "' </div>";
} } } ?>
<div class="nav_container"> <!-- logo & nav -->
<div class="logo col-xs-12 col-md-3 col-lg-3">
<a href="<?php echo home_url(); ?>">
<!-- svg logo - toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script -->
<img src="/wp-content/uploads/2016/02/PST_LOGO_SHORT_T-1.png" alt="Logo" class="logo-img col-xs-6 col-xs-offset-3 col-md-7">
</a>
</div>
<nav class="nav col-md-6 col-md-offset-2 col-lg-6 col-lg-offset-2" role="navigation">
<?php html5blank_nav(); ?>
</nav>
<div style="clear:both;"></div>
</div>
</header>
答案 0 :(得分:0)
您忘了将is_page_template( 'header-hero.php')
放入()
明确说明错误信息。
<header class="header clear" role="banner">
<?php
function check_template()
{
if (is_page_template('header-hero.php'))
{
if (!is_page())
{
echo "<div class='background-image' style='background-image: url('" . $image[0];
"' </div>";
}
}
}
?>
<div class="nav_container"> <!-- logo & nav -->
<div class="logo col-xs-12 col-md-3 col-lg-3">
<a href="<?php echo home_url(); ?>">
<!-- svg logo - toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script -->
<img src="/wp-content/uploads/2016/02/PST_LOGO_SHORT_T-1.png" alt="Logo" class="logo-img col-xs-6 col-xs-offset-3 col-md-7">
</a>
</div>
<nav class="nav col-md-6 col-md-offset-2 col-lg-6 col-lg-offset-2" role="navigation">
<?php html5blank_nav(); ?>
</nav>
<div style="clear:both;"></div>
</div>
</header>