Jump to content
MuchDev

Change loop order without reordering items

Recommended Posts

Hey there. So I am currently working out a loop that pulls a list of items from three separate parent pages. This all works perfectly except I would like to change the order that they are pulled in to the loop without re organizing the pages themselves as they are nested under three separate categories. Is this something I could use a selector with and possibly provide the client the ability to manually re-organize the order of the items that are being displayed. 

$featuredPages = $pages->find('template=Exhibition, Exhibition_Featured=1');

foreach ($featuredPages as $featuredItem){
//doin stuff 
}
	 

:rolleyes:

Share this post


Link to post
Share on other sites

You could set up a page field with a PageListSelectMultiple Inputfield Type - the user could choose the pages from anywhere in the page tree and sort as desired. Is that what you are wanting to do?

post-985-0-60621300-1408340464_thumb.png

  • Like 2

Share this post


Link to post
Share on other sites

You could set up a page field with a PageListSelectMultiple Inputfield Type - the user could choose the pages from anywhere in the page tree and sort as desired. Is that what you are wanting to do?

attachicon.gifScreen Shot 2014-08-17 at 10.40.21 PM.png

Hey thanks for the reply Adrian!

That sounds like a great idea. In my own ignorance I hadn't even thought about using this. I will give this a try tonight and see if it does what I am wanting. Mostly what I want is the ability to pull all items in my site that are "featured" on to the homepage, but those featured pages also are individually shown in different sub sections by adding a parent=.The items are displayed at many different user selected sizes so they need to be moved out of the order that they just automatically display in my loop so this will have to be manually fiddled with by the client so they all fit perfectly in the grid. 

Share this post


Link to post
Share on other sites

Absolute GENIUS!! K yes PageSelectMultiple is exactly what I want. Populate a box with a list of pages and be able to drag em around! So cool. Thanks so much for pointing this fantastic tool out. This is going to be so useful.

  • Like 1

Share this post


Link to post
Share on other sites

So now that I have found PageSelectMultiple I found another use. I would like to use it on a parent page named Artist. The page has all of their basic information and here I thought would be nice to try to implement a picker to choose all of the artworks that are children of the artist page. I tried to change the selector in the php area to $page->children before I read the warning that it is not compatable. Any way that I could get the same functionality while only having the view scoped to the children of that page? Also as a side note, I have managed to break the field all together and am now met with this friendly error when I open the field to edit it. 

Recoverable Fatal Error: Argument 1 passed to InputfieldPage::___findPagesCode() must be an instance of Page, none given (line 168 of /home/swflemin/public_html/dg/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module) 

Share this post


Link to post
Share on other sites

If you're doing it in the PHP area are you doing this?

return $page->children;

Share this post


Link to post
Share on other sites

Looks like there's a problem with InputfieldPage. PageListSelectMultiple didn't originally support findPagesCode at all, until Ryan added that feature per my request -- but in that version it was actually broken and the fix was only introduced to dev branch.

Since it's essentially a bug with with a module in wire directory, your options are ..

a) using another input field type such as AsmSelect (works fine if you're only dealing with direct children of one page),

b) using dev branch of ProcessWire (if this site is still a work in progress this might be a good idea anyway) or

c) replacing /wire/modules/Inputfield/InputfieldPage/InputfieldPage.module with newer version of same file.

Hope this helps a bit.

  • Like 5

Share this post


Link to post
Share on other sites

As always every response on this forum contains useful information, I thank you for convincing him to add it, this is a totally useful feature for this module. :) Sounds like I should just get the module from the dev branch as I would most likely need to navigate over the children of children on some items that contain extra pages to separate sections on a artist page. Thank you again, I'll post back with results! 

Share this post


Link to post
Share on other sites

Well after doing some head scratching I've decided that I will just be doing the display programatically. I have created a sub-section template that is the parent of other artworks. This will allow me to interupt the display order and move the items within the backend. I think this will end up making more sense to anyone who chooses to try and update this beast, hows this look?


	$items = $page->children;	

	foreach($items as $item){

	$generated = false;

	//Remember to not return any tags in the string if no information has been returned. 
		//option 1 - one is an item and then just print it.
		if ($item->template->name === 'items'){
			$gridSizer = $item->gridSizer;
			echo generateItem($item,$gridSizer);
			$generated = true;
		}
		//option 2 is a subsection. Print 100%width divider with text areas
		if ($item->template->name === 'itemsSection'){
			echo "<div class='grid-item masonrySection col-xs-12'>";

			if ($item->subsection_description){
				echo "<p>{$item->subsection_description}</p>";
				}
			echo "</div>";
		
			foreach ($item->children() as $subitem){
				$gridSizer = 1;
				if ($subitem->gridSizer){
				$gridSizer = $subitem->gridSizer;
				}					
				echo generateItem($subitem,$gridSizer);
			}
		}
	} 

Share this post


Link to post
Share on other sites

Looks like there's a problem with InputfieldPage. PageListSelectMultiple didn't originally support findPagesCode at all, until Ryan added that feature per my request -- but in that version it was actually broken and the fix was only introduced to dev branch.

Since it's essentially a bug with with a module in wire directory, your options are ..

a) using another input field type such as AsmSelect (works fine if you're only dealing with direct children of one page),

b) using dev branch of ProcessWire (if this site is still a work in progress this might be a good idea anyway) or

c) replacing /wire/modules/Inputfield/InputfieldPage/InputfieldPage.module with newer version of same file.

Hope this helps a bit.

Thank you! :)

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ttttim
      Is there a way to add a (new or existing) page to the top of the asmSelect list? By default they're added at the bottom. 
    • By Leftfield
      Hi,

      First, this is production realestate site, big one. So please, if any chanse to fix this without touching database, it would be great

      I have field "pstatus" as a PageReference,
      In the tree under Status as children:
      sold unavailable paused In the template "property" I have dropdown were I choose: empty (nothing); sold; unavailable or paused. If you do not choose anything, property will have active selling status.

      I need help sorting property template in this order: show all empty and than show all sold.

      1031 is Status, parent of the sold unavailable and paused.
       
      $status = $pages->get('1031')->children('sort=pstatus'); $selector[] = "sort=price, pstatus!=$status"; But I got there all except from status. I need to list "sold" too.

       
    • By j__
      On a site that lists events, I am using a repeater field 'event_time', which contains two Inputfield Time fields 'event_time_start' and 'event_time_end'. Some events take place multiple times, others just once. Here's an example for the data structure:
      event1 title: First Event event_time (1): event_time_start: 08:00 event_time_end: 09:00 event2 title: Second Event event_time (1): event_time_start: 08:00 event_time_end: 09:00 event_time (2): event_time_start: 14:00 event_time_end: 18:00 event3 title: Third Event event_time (1): event_time_start: 07:00 event_time_end: 09:30 First, I'd like to generate a list of all events, sorted by event_time_start, with every repeater item added as an actual event (similar to a SQL JOIN clause). The desired output would be:
      07:00-09:30 Third Event 08:00-09:00 First Event 08:00-09:00 Second Event 14:00-18:00 Second Event A selector like
      $pages->find('template=event,event_time.event_time_start!=,sort=event_time.event_time_start'); would only return each event page once:
      07:00-09:30 Third Event 08:00-09:00 First Event 08:00-09:00 Second Event without
      14:00-18:00 Second Event Is there a possible alteration of the selector to take all different occurrences into account?
      Also I'd like to filter for events taking place in the morning, using a selector like:
      $pages->find('template=event,event_time.event_time_start>=06:00,event_time.event_time_start<=12:00,sort=event_time.event_time_start'); However, this would only return each 'event' page, which then contains also the afternoon version of event2.
      While I have the impression these are rather simple tasks, I struggle finding a selector-based solution to it. In this example on opening times are some similarities, but it does not deal with multiple occurrences. I'd appreciate your ideas to it.
    • By Michael Steinmann
      Hello everyone,
      i guess my php knowledge is not good enough to find a solution for the following problem:
      I'm building a website where i have projects. Each project has tags like "webdesign, responsive, cms, print, flyer" etc. At the end of a project i want to recommend other projects, which have similar tags. I want to limit the recommendations to three other projects sorted by the hightest amount of same tags.
      This is how far i got:
      I'm using
      <?php $interessantes = $pages->find("tags=$page->tags, id!=$page->id"); ?> to find other projects with the same tags, excluding the page i'm already on.
      Then i'm using three foreach-functions to go through the projects i found, the tags they have and compare them with the tags of the project i'm looking at. If i have two identical tags, i count up a variable.
      <?php // Projects i have found foreach($interessantes as $interessant): $i = 0; // Tags of the projects i have found foreach($interessant->tags as $tag): // Tags of the project i'm looking at foreach($page->tags as $tagreferenz): if($tag == $tagreferenz): $i++; endif; endforeach; endforeach; endforeach; ?> You can see what it looks like in the screenshot with a bit of HTML. I marked the tags of the current project green and the identical tags of other projects red with the amount of hits below. So in this example i would want to have three projects with three similar tags and get rid of those with only two and one.

      I guess i have to put my pages into an array (with the number of hits?), sort them and echo them with "limit=3"? Unfortunately i have no idea how to do this. You probably have an even better/shorter solution. Links to other topics are welcome to and i'll try to get my head around it.
      If you need further explanation, i'll try my best.
      Best regards
    • By Cengiz Deniz
      Sorting with different selectors, pagination works good When I logged in as Admin.
      But  for visitors it does not work. I think it is cache problem.
      Any idea ?
      Thank You.
       
      https://cdeniz.com/kutuphane/kisiler/?sort=dogumtarihi
×
×
  • Create New...