WordPress多站点动态图像 - 使用条件和博客名称

时间:2021-03-22 11:48:03

this is my first post for help on here, and man do I really need it. This is the first time I've developed a client's site using multisite, and I'm having trouble applying the appropriate header image to it's site. There are six sites in all, and I'm using the same template for all six sites' front pages. Also, the front page is static and doesn't have a specific page selected.

这是我在这里的第一篇求助文章,而且我真的需要它。这是我第一次使用多站点开发客户端站点,而我在将适当的头部图像应用到其站点时遇到了问题。共有六个站点,我在所有六个站点的首页使用相同的模板。此外,首页是静态的,没有选择特定页面。

The conditional below is my attempt at specifying specific images depending on which sub-site I'm on. It keeps throwing a syntax error, (sublime calls it a parse error). I would be so grateful for any help!

以下条件是我尝试根据我所在的子站点指定特定图像。它不断抛出语法错误,(sublime称之为解析错误)。我会非常感谢任何帮助!

 <?php
if( get_bloginfo('All in with Laila Ali')) { 
   <img src="<?php bloginfo('template_directory');?>/images/Banner-LailaAli.jpg" />
} elseif{
   if( get_bloginfo('Jaimies 15 Minute Meals')) {
   <img src="<?php bloginfo('template_directory');?>/images/Banner-JamieOliver.jpg" />
}
} elseif{
   if( get_bloginfo('Lucky Dog')) {
   <img src="<?php bloginfo('template_directory');?>/images/Banner-LuckyDog.jpg" />
}
} elseif{
   if( get_bloginfo('Game Changers with Kevin Frazier')) {
   <img src="<?php bloginfo('template_directory');?>/images/Banner-GameChangers.jpg" />
}
} elseif{
   if( get_bloginfo('Recipe Rehab')) {
   <img src="<?php bloginfo('template_directory');?>/images/Banner-RecipeRehab.jpg" />
}
} else {
   <img src="<?php bloginfo('template_directory');?>/images/Banner-PetVet.jpg" />
}
?>

1 个解决方案

#1


0  

You are getting this error because you have consecutive <?php tags with HTML in between them. Things like <img src=" aren't valid php, but you are inside <?php tags, so PHP gives you an error.

您收到此错误是因为您有连续的

One of the ways you can fix this is by ending the tags when you need to switch back to HTML. Like this:

解决此问题的方法之一是在需要切换回HTML时结束标记。像这样:

<?php
if( get_bloginfo('All in with Laila Ali')) { 
   ?>
   <img src="<?php bloginfo('template_directory');?>/images/Banner-LailaAli.jpg" />
   <?php
} elseif{
   if( get_bloginfo('Jaimies 15 Minute Meals')) {
   ?>
   <img src="<?php bloginfo('template_directory');?>/images/Banner-JamieOliver.jpg" />
   <?php
   }
}
?>

Another way, is to have your PHP echo the HTML you want. Which would look something like this:

另一种方法是让你的PHP回显你想要的HTML。看起来像这样:

<?php
if( get_bloginfo('All in with Laila Ali')) { 
    echo '<img src="' . bloginfo('template_directory') . '/images/Banner-LailaAli.jpg" />';
} elseif{
   if( get_bloginfo('Jaimies 15 Minute Meals')) {
       echo '<img src="'. bloginfo('template_directory') . '/images/Banner-JamieOliver.jpg" />';
   }
}
?>

Basically, you have to remember that once you open a <?php tag, you can only put valid PHP until you close it with ?>.

基本上,你必须记住,一旦你打开一个 关闭它。

#1


0  

You are getting this error because you have consecutive <?php tags with HTML in between them. Things like <img src=" aren't valid php, but you are inside <?php tags, so PHP gives you an error.

您收到此错误是因为您有连续的

One of the ways you can fix this is by ending the tags when you need to switch back to HTML. Like this:

解决此问题的方法之一是在需要切换回HTML时结束标记。像这样:

<?php
if( get_bloginfo('All in with Laila Ali')) { 
   ?>
   <img src="<?php bloginfo('template_directory');?>/images/Banner-LailaAli.jpg" />
   <?php
} elseif{
   if( get_bloginfo('Jaimies 15 Minute Meals')) {
   ?>
   <img src="<?php bloginfo('template_directory');?>/images/Banner-JamieOliver.jpg" />
   <?php
   }
}
?>

Another way, is to have your PHP echo the HTML you want. Which would look something like this:

另一种方法是让你的PHP回显你想要的HTML。看起来像这样:

<?php
if( get_bloginfo('All in with Laila Ali')) { 
    echo '<img src="' . bloginfo('template_directory') . '/images/Banner-LailaAli.jpg" />';
} elseif{
   if( get_bloginfo('Jaimies 15 Minute Meals')) {
       echo '<img src="'. bloginfo('template_directory') . '/images/Banner-JamieOliver.jpg" />';
   }
}
?>

Basically, you have to remember that once you open a <?php tag, you can only put valid PHP until you close it with ?>.

基本上,你必须记住,一旦你打开一个 关闭它。