Jump to content

Wanting To Create A Page Of Page Links Formatted.


MuchDev
 Share

Recommended Posts

So I have found nearly exactly what I am looking for in a pretty old post, but was wondering if someone had a new way that possibly utilized pagination to format a full list of titles. 

 
 
Currently I have a page selector that I am using to select specific "artists". I am attempting to create a very simple list view where I return some of the fields from the pages that have the pagefield as "contemporary" as a link and a rel tag for an image. If I point this to the contemporary section I will recieve 83 results. What I would like to do is simple, if in this case there are 83, then I would like 21 per column, in its own div. any mathys out there wanna help me make a loop? Thanks in advance :)
$out = "";
$pos = 0; //current position in list
$out .= '<div class="row">';	

//this block counts artists in relevant category based on $dept var set above.
//it then will set the amount to be shown per column and how many columns to display based on count
	if ($dept = "Contemporary"){
		$select = "artwork_dept=/departments/contemporary/";
		$count = count($pages->get("/artists/")->children($select));
		$initCount = $count;
		$entries = round($count / 4);//entries per line
		$artists = $pages->get("/artists/")->children($select);
		$artists = $artists->reverse();
		echo $entries;
	}
	
	//grab chunks of artists and loop them in roughly equal amounts

		$rows = 7;
$totalCount = count($jurisdictionsPageChildren);
$rowCount = ceil($totalCount / $rows);
$mod = $totalCount % $rows; // this will tell us how many rows will have more pages than the others
$firstInRow = 0;
$i = 1;
while ($i <= $rows){
   $mainContent .= "<div class='columns six";
   if($i == 1) $mainContent .= " alpha";
   if($i == $rows) $mainContent .= " omega";
   $mainContent .= "'>";
   if($i <= $mod){ // do this when we want one more page on the row
      $sliced = $jurisdictionsPageChildren->slice($firstInRow, $rowCount);
      $firstInRow += $rowCount;
   }else{ // do this when we want one less page on the row
      $sliced = $jurisdictionsPageChildren->slice($firstInRow, $rowCount-1);
      $firstInRow += $rowCount-1;
   }
   foreach($sliced as $p){
      $mainContent .= "<h2><a$class href='{$p->url}' title='{$p->title}'>{$p->title}</a></h2>";
   }
   $mainContent .= "</div>";
   $i++;
}

Here is the sample from the original link for reference.

Link to comment
Share on other sites

So I ended up fidling all day and I am happy with the results :) Just took a bit of looping, really tested my skills:) Here is a code chunk to get you goin 

//this block counts artists in relevant category based on $dept var set above.
//it then will set the amount to be shown per column and how many columns to display based on count
	if ($dept = "Contemporary"){
		$select = "artwork_dept=/departments/contemporary/";
		$count = count($pages->get("/artists/contemporary/")->children($select));
		$initCount = $count;
		$entriesper = ceil($count / 4);//entries per line
		$artists = $pages->get("/artists/contemporary")->children($select);
		$artists = $artists;
		echo $entries;
	}elseif ($dept = "Modern"){//todo make the actually work
		$count = count($pages->get("/artists/modern/")->children("artwork_dept=/departments/modern/"));
	}elseif ($dept = "Antique"){//todo make the actually work
		$count = count($pages->get("/artists/modern/")->children("artwork_dept=/departments/antique/"));
	}
	
	//grab chunks of artists
	
	$i = 1;
	$firstInRow = 0;
	$mod = $count / $entriesper;
	
	while($i<$entriesper){
	$out .= '<div class="col-md-3">';
	$sliced = $artists->slice($firstInRow,$entriesper);
	$firstInRow += $entriesper;
	
	$out .= '<ul class="artist list">';
		foreach($sliced as $artist){
			if ($artist->artist_featured_image->url){
				$img = $artist->artist_featured_image->width(175)->url;
			}
		$fullname = "";
		$fullname = $artist->artist_firstname.' '.$artist->artist_lastname;
		$link = $artist->url;
		$out .= '<li><a title="'.$fullname.'" class="preview" href="'.$link.'" rel="'.$img.'" >'.$artist->artist_firstname.'<strong> '.$artist->artist_lastname.'</strong></a></li>';
		}		
	
	$out .= '</div>';
	$i++;
	}		
		
$out .= '</div>';//end row		
echo $out;
?>
  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...