dtdh11647 2014-10-05 23:51
浏览 55

基于分页查看的动态轮播横幅

I trying to produce a dynamic carousel banner to update the image, headers, text, links & alts based on the content page being viewed.

The site is being coded in .php & using the bootstrap CSS framework. I've broken the site into three main parts... Header, "Content" and Footer.

I'm calling the function img-banner as part of the header.php but wish to use variables stored in the "content" pages which will determine the images etc being viewed.

Calling the function:

<div class="img-banner">
  <?php include ("functions/img-banner.php"); ?>    
<!-- closing img-banner -->
</div>

The function:

<?php
function img_banner()
{   
?>
<div class="carousel-inner">
  <div class="item active"> <img src="<?php echo $img1;?>" alt="<?php echo $alt1;?>">
    <div class="container">
      <div class="carousel-caption">
        <h1><?php echo $head1;?></h1>
        <p><?php echo $text1;?></p>
        <p><a class="btn btn-lg btn-primary" href="<?php echo $link1;?>" role="button">Learn More<i class="fa fa-chevron-details"></i></a></p>
     </div>
  </div>
</div>
<div class="item"> <img src="<?php echo $img2;?>" alt="<?php echo $alt2;?>">
  <div class="container">
    <div class="carousel-caption">
      <h1><?php echo $head2;?></h1>
      <p><?php echo $text2;?></p>
      <p><a class="btn btn-lg btn-primary" href="<?php echo $link2;?>" role="button">Learn More<i class="fa fa-chevron-right"></i></a></p>
    </div>
  </div>
</div>
<div class="item"> <img src="<?php echo $img3;?>" alt="<?php echo $alt3;?>">
  <div class="container">
    <div class="carousel-caption">
      <h1><?php echo $head3;?></h1>
      <p><?php echo $text3;?></p>
      <p><a class="btn btn-lg btn-primary" href="<?php echo $link3;?>" role="button">Learn More<i class="fa fa-chevron-right"></i></a></p>
    </div>
   </div>
  </div>
 </div>
<?php
}
?>

I'm a little stumped and have tried (obviously unsuccessfully lol) global and SESSION variables but cant get them to work correctly.

I'd appreciate confirmation on the best method to implement the above so I can read up and figure this out. My main goal is to have a cms style admin panel to update the images.

Thanks!

  • 写回答

1条回答 默认 最新

  • duan6832168 2014-10-06 00:02
    关注

    First of all, the function does not have access to the $img1-$img3 variables as you're not passing them to the function.

    Secondly, you really do not require a function to do this simple task.

    Last but not least, you are not even calling the function, only including it's file.

    Here's how you should do this:

    <div class="img-banner">
      <?php include ("img-banner.php"); ?>    
    <!-- closing img-banner -->
    </div>
    

    And the img-banner.php:

    <div class="carousel-inner">
      <div class="item active"> <img src="<?php echo $img1;?>" alt="<?php echo $alt1;?>">
        <div class="container">
          <div class="carousel-caption">
            <h1><?php echo $head1;?></h1>
            <p><?php echo $text1;?></p>
            <p><a class="btn btn-lg btn-primary" href="<?php echo $link1;?>" role="button">Learn More<i class="fa fa-chevron-details"></i></a></p>
         </div>
      </div>
    </div>
    <div class="item"> <img src="<?php echo $img2;?>" alt="<?php echo $alt2;?>">
      <div class="container">
        <div class="carousel-caption">
          <h1><?php echo $head2;?></h1>
          <p><?php echo $text2;?></p>
          <p><a class="btn btn-lg btn-primary" href="<?php echo $link2;?>" role="button">Learn More<i class="fa fa-chevron-right"></i></a></p>
        </div>
      </div>
    </div>
    <div class="item"> <img src="<?php echo $img3;?>" alt="<?php echo $alt3;?>">
      <div class="container">
        <div class="carousel-caption">
          <h1><?php echo $head3;?></h1>
          <p><?php echo $text3;?></p>
          <p><a class="btn btn-lg btn-primary" href="<?php echo $link3;?>" role="button">Learn More<i class="fa fa-chevron-right"></i></a></p>
        </div>
       </div>
      </div>
     </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?