How to loop and display (n) feeds using simpleXML and position()
문제
I am using simpleXML and I want to loop though the feed to only display 5 shows using the position() method, but have no joy in getting it to work
foreach($xml->sortedXPath('TV[position() < 5 and ProgrammeName="MTV"]', 'TransmissionDate', SORT_DESC) as $i => $item)
{
print "<a href='?v=".$item->ID."&a=false' class='link'>\n";
print "\t<span class=\"text\">" .trunc($item->ShortSynopsis,25, " "). "</span>\n";
print "\t</a>";
}
any suggestions on how I can get this working
this is the XML data I am working with
올바른 솔루션이 없습니다
다른 팁
This feels like a repost, but anyway...
NiseNise wants to sort nodes then keep the top 5. The problem is that this XPath expression selects the first 5 nodes in the document, then the method sorts them. What you need to do is sort all the nodes then only process the first 5.
foreach($xml->sortedXPath('TV[ProgrammeName="MTV"]', 'TransmissionDate', SORT_DESC) as $i => $item)
{
if ($i > 5)
{
break;
}
print "<a href='?v=".$item->ID."&a=false' class='link'>\n";
// etc...
}
I forgot to mention, sortedXPath()
isn't part of SimpleXML, it's part of a library extending SimpleXML, hence the retagging.
기능 스테이플 링을 사용하여이를 달성 할 수 있습니다.단순한 요소 파일을 기능에 배포하고 웹 응용 프로그램 수준에서 활성화하십시오.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation Id="the guid of the feature to staple to new sites" TemplateName="GLOBAL"/>
</Elements>
.
또한이 오히려 유익한 SP.SE 포스트 기능 스테이플 링에 대한 정보 :