2012-11-25 34 views
0

我有项目要显示在我的WordPress的侧边栏。比方说div1,div2,div3。根据主要内容的高度重复wordpress中的侧边栏项目?

我的客户想重复侧栏中的项目顺序来填充侧栏的高度以匹配主内容区域的高度。因此,如果每个div的高度为200px,并且给定页面上主div的内容为1000px,则应该有div1,div2,div3,div1,div2。

我知道如何编写PHP代码并编写循环,但是如何知道要运行多少个循环?

尽管我觉得这有点傻,但我的客户坚持这一点。

回答

0

我结束了与jQuery做这个。它不是一个浮动的侧边栏,它实际上会根据需要将img标签添加到已有的任何内容中,直到不再适合。

<script type="text/javascript"> 
$(function() { 
    var contentHeight = $('#content').height(); 
    var adList = [ 
     '<img class="ad" src="----url to first ad -----" />', 
     '<img class="ad" src="----url to second ad -----" />', 
     '<img class="ad" src="----url to third ad -----" />', 
     '<img class="ad" src="----url to fourth ad -----" />', 
     '<img class="ad" src="----url to fifth ad -----" />' 
     ]; 
    var adHeight = 285; 
    var numRequiredAds = adList.length; 
    var heightDiff = contentHeight - (numRequiredAds * adHeight); 
    var numAds = Math.floor(heightDiff/adHeight); 
    if (heightDiff > adHeight){ 
     for (var i = 0; i < numAds ; i++) { 
      $('#primary').append(adList[i % adList.length]); 
     }; 
    } 

}); 

0

我想到的一个解决方案是使用JavaScript(或JQuery)来获取主要内容的高度,并确定可以在侧面添加多少DIV。

编辑:这是不是有效的方法来做,但假设在循环中所有的侧栏内容将被显示。然后,在JavaScript中决定要显示多少个div。

0

这种类型的效果被称为“浮动边栏”。我们将有一些wordpress插件可用。

简单的Google搜索将找到解决您的问题。

一个谷歌搜索结果的是:

http://www.strx.it/2010/11/wordpress-floating-sidebar-plugin/

+0

我知道如何使用谷歌,这不是我问布特虽然。我不需要侧栏来关注用户,我想根据需要填充侧栏。请重新阅读这个问题。 – Steve

相关问题