Jump to content

Retrieving Tag Results In Separate Sections


fay
 Share

Recommended Posts

I didn't exactly just start using ProcessWire. But does anyone know how would I go about retrieving the pages with a certain tag into separate sections based on their parent? Problem lies in the fact that both photos and featurettes (videos) share the same tags, and their thumbnails have a different aspect ratio. Which is pretty much why I'd like to have them separated, if a certain tag has been used on both content types. Parent names are "photos" and "featurettes".

Needless to say, the current code isn't really good nor a beauty to look at. But I've attached it, and I'd appreciate any help.

$thisTag = $page->title;
$tdsphotos = wire("pages")->find("tagsx.title=$thisTag, limit=8, sort=-created");
$pagination = $tdsphotos->renderPager(array(
'nextItemLabel' => "Next",
'previousItemLabel' => "Prev",
'listMarkup' => "<ul class='pagination'>{out}</ul>",
'itemMarkup' => "<li>{out}</li>",
'linkMarkup' => "<a href='{url}'>{out}</a>"
));
echo "<div class=\"littleboxes\">\n";
foreach($tdsphotos as $tdsphoto){
$otep = $tdsphoto->images->first();
$thumb = $tdsphoto->images->first()->size(210, 210);
$out .="<div class=\"inabox\">";
$out .="\n<a href=\"{$tdsphoto->url}\"><img alt=\"{$otep->description}\" title=\"{$otep->description}\" class=\"img-thumbnail img-responsive\" itemprop=\"thumbnailUrl\" src=\"{$thumb->url()}\" width=\"{$thumb->width}\" height=\"{$thumb->height}\"></a>";
$out .="<h6 itemprop=\"name\"><a href=\"{$tdsphoto->url}\">{$tdsphoto->title}</a></h6>";
$out .="\n</div>\n"; }
echo $out;
echo "</div>\n";
echo $pagination;

Thanks!

Link to comment
Share on other sites

Are they using different templates? In which case you can either add their templates to the search, or divide them up later by saying

if($tdsphoto->template =="name-of-template") {  

and then set out the layout you want for each type.

  • Like 1
Link to comment
Share on other sites

There's a little bit of unnecessary code in your original post (and a bit of mixing $page and wire('pages') ) during the first two lines - you could also write it like this if it helps:

$tdsphotos = $pages->find("tagsx.title=$page->title, limit=8, sort=-created");

One thing I would like to mention to everyone is that in double quotes you can to this: $page->title but not $page->somepagefield->somethingelse - as soon as you throw in the second -> (I'm not sure of the technical term!) you need to wrap the whole thing in curly braces like this: {$page->somepagefield->somethingelse} or you'll be troubleshooting it for hours like I did a few months back :D

Alternatively you can concatenate as usual to avoid the curly braces requirement, so:

$tdsphotos = $pages->find("tagsx.title=" . $page->title . ", limit=8, sort=-created");
  • Like 2
Link to comment
Share on other sites

Ah, that is why I have used curly brackets everywhere - I had forgotten. I knew there had to be a good reason.

Also, I tend to use single quotes rather than \" - it just makes it more readable. No idea whether it is good practice or not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...