Posts: 11
Threads: 3
Joined: Sep 2018
2019-02-09, 02:29:01
(This post was last modified: 2019-02-09, 02:29:48 by SalamandersPL.)
Hi. Relatively small problem.
I can not order the subpages i want to echo with the loop:
PHP Code:
<?php
$children=getChildren('term-conditions');
$ordered = subval_sort($children, 'menuOrder');
?>
<div class="parent">
<?php foreach ($ordered as $child){?>
<h2><?php getPageField($child, 'title'); ?></h2>
<?php }; ?>
</div>
The
$ordered variable do nothing. Why?
Posts: 11
Threads: 3
Joined: Sep 2018
Hello?
Can anyone can help me to order this list?
Posts: 44
Threads: 8
Joined: May 2014
(2019-02-15, 03:05:04)SalamandersPL Wrote: Hello?
Can anyone can help me to order this list?
In theme folder create functions.php and add this code:
PHP Code:
function getChildrenTitle($page)
{
$children = getChildren($page);
foreach ($children as $subpage)
{
$title = returnPageField($subpage,'title');
echo '<div class="parent">';
echo '<h2>'.$title.'</h2>';
echo '</div>';
}
}
Call the function in template:
PHP Code:
<?php getChildrenTitle('term-conditions');?>
Posts: 11
Threads: 3
Joined: Sep 2018
2019-02-18, 19:27:07
(This post was last modified: 2019-02-18, 20:31:56 by SalamandersPL.)
Still, i have them ordered different way on the page than in GetSimple.
https://salamanders-studio.com/temp/getsimple.png
https://salamanders-studio.com/temp/result.png
(if you ask about my getsimple look: this is a css plugin, not modified core)
Posts: 44
Threads: 8
Joined: May 2014
(2019-02-18, 19:27:07)SalamandersPL Wrote: Still, i have them ordered different way on the page than in GetSimple.
https://salamanders-studio.com/temp/getsimple.png
https://salamanders-studio.com/temp/result.png
(if you ask about my getsimple look: this is a css plugin, not modified core)
I see that you use numbers in the title (h2).
So try this code:
PHP Code:
function getChildrenTitle($page)
{
$children = getChildren($page);
$pagesSorted = subval_sort($children, SORT_NUMERIC);
$pagesSorted = array_reverse($pagesSorted, true);
foreach ($pagesSorted as $subpage)
{
$title = returnPageField($subpage,'title');
echo '<div class="parent">';
echo '<h2>'.$title.'</h2>';
echo '</div>';
}
}
Posts: 11
Threads: 3
Joined: Sep 2018
2019-02-20, 09:43:03
(This post was last modified: 2019-02-20, 09:45:38 by SalamandersPL.)
Your code gave me this:
https://www.salamanders-studio.com/temp/result2.png
Well, it would be great to have that option to sort it same as displayed in CMS.
And what is "menuOrder" for?
Posts: 44
Threads: 8
Joined: May 2014
(2019-02-20, 09:43:03)SalamandersPL Wrote: Your code gave me this:
https://www.salamanders-studio.com/temp/result2.png
Well, it would be great to have that option to sort it same as displayed in CMS.
And what is "menuOrder" for?
Do you have install i18N plugin? If you have, create a new component (Theme->Edit Components) with this code:
Component name -> custom-nav
PHP Code:
<li class="<?php echo $item->classes; ?>">
<a href="<?php echo htmlspecialchars($item->link); ?>">
<?php echo htmlspecialchars($item->title); ?>
</a>
<?php if ($item->isOpen) { ?>
<ul><?php $item->outputChildren(); ?></ul>
<?php } ?>
</li>
In template add this:
PHP Code:
<?php if (return_page_slug()=='term-conditions') { ?>
<ul class="tree">
<?php get_i18n_navigation('term-conditions',1,100,I18N_SHOW_NORMAL, 'custom-nav'); ?>
</ul>
<?php } ?>
Posts: 11
Threads: 3
Joined: Sep 2018
You are a great man. Thank you!
Posts: 44
Threads: 8
Joined: May 2014
(2019-02-20, 22:34:40)SalamandersPL Wrote: You are a great man. Thank you!
You're welcome!