我真的很挣扎,想知道是否有人可以花一些时间来看看这个代码块。
原始行看起来像这样:
$home_collectionsx=get_home_page_promoted_collections();
这会将所有提升的主页项目带回主页并在主页上显示。然而,我只是想使用相同的代码和数组函数拉出1个项目,为此目的的id为5,所以我认为添加=array(5)
或(array (5))
会起作用 - 但它不会。 / p>
我希望这是一件简单的事情,或者我错过或没有正确写的东西。
<?php
if(!hook("EditorsPick")):
/* ------------ Collections promoted to the home page ------------------- */
$home_collectionsx=get_home_page_promoted_collections (array(5));
foreach ($home_collectionsx as $home_collectionx)
{
?>
<div class="EditorsPick">
<div class="HomePanel"><div class="HomePanelINtopEditors">
<div class="HomePanelINtopHeader">Editors Pick</div>
<div class="HomePanelINtopText">This is the editors pick of Asset Space...</div>
<div class="EditorsPicImage"><div style="padding-top:<?php echo floor((155-$home_collectionx["thumb_height"])/2) ?>px; margin-top: -24px; margin-bottom: -15px;">
<a href="<?php echo $baseurl_short?>pages/search.php?search=!collection<?php echo $home_collectionx["ref"] ?>" onClick="return CentralSpaceLoad(this,true);"><img class="ImageBorder" src="<?php echo get_resource_path($home_collectionx["home_page_image"],false,"thm",false) ?>" width="<?php echo $home_collectionx["thumb_width"] ?>" height="<?php echo $home_collectionx["thumb_height"] ?>" /></div>
</div></div>
</div>
</div>
</div>
<?php
}
endif; # end hook homefeaturedcol
?>
这是上面代码连接到DB本身的函数...
function get_home_page_promoted_collections()
{
return sql_query("select collection.ref,collection.home_page_publish,collection.home_page_text,collection.home_page_image,resource.thumb_height,resource.thumb_width from collection left outer join resource on collection.home_page_image=resource.ref where collection.public=1 and collection.home_page_publish=1 order by collection.ref desc");
}
非常感谢任何帮助: - )
非常感谢 富
答案 0 :(得分:1)
该函数不带参数:get_home_page_promoted_collections()
你想要这样的东西:
$home_collectionsx=get_home_page_promoted_collections(5);
和
function get_home_page_promoted_collections($id=null)
{
$filterClause = '';
if(!is_null($id))
{
//to only return this id
$filterClause = ' AND collection.ref = '.intval($id);
//to get all but that id
$filterClause = ' AND collection.ref != '.intval($id);
}
return sql_query("SELECT collection.ref,collection.home_page_publish,collection.home_page_text,collection.home_page_image,resource.thumb_height,resource.thumb_width FROM collection LEFT OUTER JOIN resource on collection.home_page_image=resource.ref WHERE collection.public=1 AND collection.home_page_publish=1".$filterClause." ORDER BY collection.ref DESC");
}