Cengiz Deniz Posted February 20, 2017 Share Posted February 20, 2017 I have a long list for page childrens. I want to make short list with three columns. I think it is able to with an API. How ? sample: https://cdeniz.com/kisiler.html Link to comment Share on other sites More sharing options...
adrian Posted February 20, 2017 Share Posted February 20, 2017 You can accomplish this in two main ways - PHP via the modulus operator (google php modulus columns) or via css columns. 1 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 20, 2017 Author Share Posted February 20, 2017 Thank You. I made following code and it works. But I am not happy. Should be better way ? $kisi_sayisi=$page->numChildren ; $satir_sayisi=floor($kisi_sayisi/ 3); echo '<center><table width="100%" border="0" cellspacing=0 cellpadding="0"> <tr align="left" valign="top"><td><ul>'; for ($i=1 ; $i<$satir_sayisi+2;$i++) { $child=$page->children("sort=title")->eq($i-1); echo '<li><a href="'.$child->url.'">'.$child->title.'</a></li>';} echo '</ul></td><td><ul>'; for ($i=$satir_sayisi+2 ; $i<2*$satir_sayisi+3;$i++) { $child=$page->children("sort=title")->eq($i-1); echo '<li><a href="'.$child->url.'">'.$child->title.'</a></li>';} echo '</ul></td><td><ul>'; for ($i=2*$satir_sayisi+3 ; $i<3*$satir_sayisi+3;$i++) { $child=$page->children("sort=title")->eq($i-1); echo '<li><a href="'.$child->url.'">'.$child->title.'</a></li>';} echo '</ul></td></tr></table></center>'; https://cdeniz.com/pw/kisiler/ Link to comment Share on other sites More sharing options...
adrian Posted February 20, 2017 Share Posted February 20, 2017 6 minutes ago, Cengiz Deniz said: Should be better way ? See my post Modulus operator - note that the style for the ul columns in this example is rough, but you should get the idea how it's done. foreach($page->children() as $i => $item) { if($i%3==0) echo '</ul><ul style="width:150px;float:left">'; echo "<li>{$item->title}</li>"; } echo '</ul>'; CSS Columns echo '<ul>'; foreach($page->children() as $i => $item) { echo "<li>{$item->title}</li>"; } echo '</ul>'; ul { -moz-column-count: 4; -moz-column-gap: 20px; -webkit-column-count: 4; -webkit-column-gap: 20px; column-count: 4; column-gap: 20px; } 2 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 20, 2017 Author Share Posted February 20, 2017 Woow awful. But I want to vertical order. I think you should have an idea Link to comment Share on other sites More sharing options...
adrian Posted February 20, 2017 Share Posted February 20, 2017 5 minutes ago, Cengiz Deniz said: Woow awful. Not sure if there is a translation problem there, but not typically the way to say thanks If you need to sort, just add: "sort=name" as the selector for children(), eg $page->children("sort=name") Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 20, 2017 Author Share Posted February 20, 2017 i want to say amazing. yes it was translation mistake I can order. But problem is your code it is not vertical column order. 1 Link to comment Share on other sites More sharing options...
adrian Posted February 20, 2017 Share Posted February 20, 2017 2 minutes ago, Cengiz Deniz said: i want to say amazing. yes it was translation mistake Yeah, I guess it is very weird that "awe-some" is great, but "aw-ful" is a complete lack awe, or maybe it's full of awe about how bad it is - English is weird!! As for the vertical column order, it seems fine here. Maybe you could show what you are getting and what you expect in case I am misunderstanding. Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 20, 2017 Author Share Posted February 20, 2017 Your php code makes groups and order is horizontal: Your css code seems good. But only first column has dots. thank you Link to comment Share on other sites More sharing options...
adrian Posted February 20, 2017 Share Posted February 20, 2017 Ah yes - sorry, my fault about the php modulus approach - you need to count the number of items and divide by three and do a ceil() to make it an integer and use that number because it is breaking on rows and not actually columns. To be honest, I don't really see the point in using the PHP approach these days since css columns is well supported. As for the first column having the dot list-style-type - do you want them all to have dots, or none? It looks like perhaps you have another css rule that is interfering, but I am sure you have that figured out by now. 1 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 21, 2017 Author Share Posted February 21, 2017 Yes. thanks a lot. But i hope an API like that $page->children($from,$to) this would solve that type problems easy. Link to comment Share on other sites More sharing options...
adrian Posted February 21, 2017 Share Posted February 21, 2017 1 hour ago, Cengiz Deniz said: Yes. thanks a lot. But i hope an API like that $page->children($from,$to) this would solve that type problems easy. $page->children("start=2, limit=2") Although I don't really see the reason to do that when css columns make it so easy. Also, rather than that, you should probably do an in memory selector to reduce unnecessary db calls, so: $children = $page->children(); $children->filter("start=2, limit=2"); Also, if you haven't discovered TracyDebugger yet, the console panel is the perfect place to test and learn this stuff: 2 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 22, 2017 Author Share Posted February 22, 2017 thank you. i think i am stupid. since two days i could not run magical tool TracyDebugger and following code $children = $page->children(); $sayfalar= $children->filter("start=2, limit=2")->each("title"); echo $sayfalar; Link to comment Share on other sites More sharing options...
adrian Posted February 22, 2017 Share Posted February 22, 2017 5 minutes ago, Cengiz Deniz said: echo $sayfalar; will give an "Array to string conversion on line: 3" error. In Tracy you can dump the array with d(), but in your template code you will likely want to leave off the ->each("title") and foreach through $sayfalar to return various fields. Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted February 23, 2017 Author Share Posted February 23, 2017 Finaly i did Thank You Adrian https://cdeniz.com/konular/ $sayi= $page->children->count; $kolum1=ceil($sayi/4); $kolum2=2*$kolum1; $kolum3=3*$kolum1; echo "<table border='0' width='100%'><tr><td>"; renderNav($page->children("start=0, limit=$kolum1-1")); echo "</td><td valign='top'>"; renderNav($page->children("start=$kolum1,limit=$kolum1-1")); echo "</td><td valign='top'>"; renderNav($page->children("start=$kolum2,limit=$kolum1-1")); echo "</td><td valign='top'>"; renderNav($page->children("start=$kolum3,limit=$kolum1-1")); echo "</td></tr></table>"; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now