根据条件重新排序HTML元素


Reorder an HTML element based on a condition?

Wordpress在某个页面的'page-wrap'之前加载一个横幅。

通过包含文件'header.php'来加载banner

但是,如果它在不同的页面上,我想在"main-wrap"之后加载它。

 <body> 
    <div id="page-wrap">
      <div id="main-wrap">
        <div id="main-header">
        <?php include ("./../included/header.php"); ?>
    </div>
 </div>

我想指出,我通过创建一个条件语句解决了这个问题,该语句包含一个备用的header2.php文件。所以,两个单独的文件解决了这个问题。

像这样使用if..else...

<div id="main-header">
    <?php 
     if(condition) {
         include ("./../included/header.php"); 
     }
     ?>
</div>

使用if语句。使用两个语句,这样你就不会得到重复的横幅。

<body> 
   <?php
   if( yourcondition ){
     include ("./../included/header.php");
   }
   ?>
    <div id="page-wrap">
      <div id="main-wrap">
        <div id="main-header">
   <?php
   if( yourcondition ){
     include ("./../included/header.php");
   }
   ?>
</div>