2013-05-12 58 views
0

我刚开始使用ProcessWire系统并真正享受它。使用ProcessWire选择随机页面图像

在我的主页上,我想从随机页面显示图像。只要该页面是ID为'1010'的父页面的子页面,页面就可以是ANY页面。

是否有可能,如果是这样,我怎么做到这一点?

我目前的显示主页图像的代码是这样的: if($page->image) echo "<img src='{$page->image->url}'>";但是,我想从上面的父ID的任何子页面中选择一个随机图像。我发现this,但不确定它是否有任何用处。

为:-)

回答

1

你应该试着在你的模板的代码是这样的指针非常感谢(假设你的像场被称为image):

/* Find all children of page with ID 1010 that include an image */ 
$allChildPages = $pages->find('parent=1010,image.count>0'); 

/* Select a page from all children in the PageArray randomly */ 
$randomChildPage = $allChildPages->getRandom(); 

if ($randomChildPage->image) { 
    echo "<img src='{$randomChildPage->image->url}'>"; 
} 

看一看有关代码:

也看看this forum thread其中几个策略来随机化来自不同页面的图像进行讨论。