admin管理员组文章数量:1414939
I wrote a widget but I need to use the variables from one widget in another...both widgets are in the same dynamic sidebar.
This is what I am trying to do: I wrote a widget that adds a footer to the bottom of an image slider widget. When I add the footer widget under the slider widget...the footer shows up.
The problem is that I need the footer widget to appear within the slider < div > set, not under it. For example:
<div id="this-is-the-slider-widget">
<div>do slider stuff here</div>
<div id="I-want-the-footer-widget-to-start-here">
<div>display footer widget here</div>
</div><!-- close footer widget-->
</div><!-- close slider widget -->
However; the footer widget displays right after the slider widget is done.
<div id="this-is-the-slider-widget">
<div>do slider image show</div>
</div><!-- cose slider widget -->
<div id="footer-widget">
<div>display footer here</div>
</div><!-- close footer widget -->
Otherwise; the bottom css of the slider pushes the footer down and messes things up. If I adjust the css so the footer and slider have a zero bottom margin and padding then the content below the banner has no spacing when the footer widget is not present.
This is how I want it to look, flush:
...but widgets are executed in order so this is what happens:
I could solve the problem by using two css classes and check if the widget exists and run .yes-widget {} or .no-widget{} but I think it's is a lot cleaner to just be able to pass the variables from one widget to another.
How I got the first image to work (but none of the variables form the footer widget are passed)...I included the footer html within the slider's widget like this:
<div id="this-is-the-slider-widget">
<div>do slider stuff here</div>
<div id="display-footer-here>
<?php global $ct_on, $child_dir;
if($ct_on && file_exists($child_dir.'/library/includes/yif-top-banner-section-footer.php')) {
include_once ($child_dir.'/library/includes/yif-top-banner-section-footer.php');
} ?>
</div><!-- end footer widget -->
</div><!-- end slider widget -->
This is the footer html that is included:
<div class="top-banner-section-footer">
<div class="top-banner-section-footer-wrapper">
<a href="<?php echo $fltitle;?>" class="footerbox left-box no-underline">
<h3><?php echo $fltitle;?></h3>
<p><?php echo $fltext;?></p>
</a>
<a href="<?php echo $fmlink;?>" class="footerbox middle-box no-underline">
<h3><?php echo $fmtitle;?></h3>
<p><?php echo $fmtext;?></p>
</a>
<a href="<?php echo $frlink;?>" class="footerbox right-box no-underline">
<h3><?php echo $frtitle;?></h3>
<p><?php echo $frtext;?></p>
</a>
</div><!-- /.top-banner-section-footer-wrapper -->
</div><!-- /.top-banner-section-footer -->
Unless you have a better way then included the footer html right where I want the footer to execute...how do I get the variables form the footer widget to work in in the included footer html file?
For example, the footer widget saves this variable: $frlink. How do I pass $frlink to the included file?
I have tried GLOBAL but I am not sure which function of the slider widget to add it. For example, the function that has the widget Constructor, where it prints the widget, saves the widget, the widget form in the backend , etc.
I wrote a widget but I need to use the variables from one widget in another...both widgets are in the same dynamic sidebar.
This is what I am trying to do: I wrote a widget that adds a footer to the bottom of an image slider widget. When I add the footer widget under the slider widget...the footer shows up.
The problem is that I need the footer widget to appear within the slider < div > set, not under it. For example:
<div id="this-is-the-slider-widget">
<div>do slider stuff here</div>
<div id="I-want-the-footer-widget-to-start-here">
<div>display footer widget here</div>
</div><!-- close footer widget-->
</div><!-- close slider widget -->
However; the footer widget displays right after the slider widget is done.
<div id="this-is-the-slider-widget">
<div>do slider image show</div>
</div><!-- cose slider widget -->
<div id="footer-widget">
<div>display footer here</div>
</div><!-- close footer widget -->
Otherwise; the bottom css of the slider pushes the footer down and messes things up. If I adjust the css so the footer and slider have a zero bottom margin and padding then the content below the banner has no spacing when the footer widget is not present.
This is how I want it to look, flush:
...but widgets are executed in order so this is what happens:
I could solve the problem by using two css classes and check if the widget exists and run .yes-widget {} or .no-widget{} but I think it's is a lot cleaner to just be able to pass the variables from one widget to another.
How I got the first image to work (but none of the variables form the footer widget are passed)...I included the footer html within the slider's widget like this:
<div id="this-is-the-slider-widget">
<div>do slider stuff here</div>
<div id="display-footer-here>
<?php global $ct_on, $child_dir;
if($ct_on && file_exists($child_dir.'/library/includes/yif-top-banner-section-footer.php')) {
include_once ($child_dir.'/library/includes/yif-top-banner-section-footer.php');
} ?>
</div><!-- end footer widget -->
</div><!-- end slider widget -->
This is the footer html that is included:
<div class="top-banner-section-footer">
<div class="top-banner-section-footer-wrapper">
<a href="<?php echo $fltitle;?>" class="footerbox left-box no-underline">
<h3><?php echo $fltitle;?></h3>
<p><?php echo $fltext;?></p>
</a>
<a href="<?php echo $fmlink;?>" class="footerbox middle-box no-underline">
<h3><?php echo $fmtitle;?></h3>
<p><?php echo $fmtext;?></p>
</a>
<a href="<?php echo $frlink;?>" class="footerbox right-box no-underline">
<h3><?php echo $frtitle;?></h3>
<p><?php echo $frtext;?></p>
</a>
</div><!-- /.top-banner-section-footer-wrapper -->
</div><!-- /.top-banner-section-footer -->
Unless you have a better way then included the footer html right where I want the footer to execute...how do I get the variables form the footer widget to work in in the included footer html file?
For example, the footer widget saves this variable: $frlink. How do I pass $frlink to the included file?
I have tried GLOBAL but I am not sure which function of the slider widget to add it. For example, the function that has the widget Constructor, where it prints the widget, saves the widget, the widget form in the backend , etc.
Share Improve this question edited Aug 25, 2019 at 20:44 Glorfindel 6093 gold badges10 silver badges18 bronze badges asked Aug 12, 2012 at 21:39 JasonJason 6062 gold badges11 silver badges21 bronze badges1 Answer
Reset to default 1You don't need to make it global.
If your include a file from within a functions scope, any variables that you defined in that function (before that point) will be exposed in the included file as well.
But because the variable you are talking about represents the state of the footer file inclusion (if I understood correctly), you can make it a static variable:
class You_Widget{
protected static
$footerIncluded = false;
public function widget(){
// this will only run once
if(!self::$footerIncluded){
include __DIR__ . '/footer.php';
self::$footerIncluded = true;
}
}
}
本文标签: globalsPass variables from one widget to another widget
版权声明:本文标题:globals - Pass variables from one widget to another widget 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216046a2648172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论