Jump to content

$page->children list with columns


Cengiz Deniz
 Share

Recommended Posts

Thank You. I made following code and it works. But I am not happy. Should be better way ? :undecided:

 

    $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

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;
}

 

 

  • Like 2
Link to comment
Share on other sites

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

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

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.

  • Like 1
Link to comment
Share on other sites

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:

58abe2e719c79_ScreenShot2017-02-20at10_48_54PM.png.d06e594888d81dd6729f6c7173a672d9.png

  • Like 2
Link to comment
Share on other sites

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

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

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...