isfolder - [0|1] Whether or not the document is a folder.
<?php
/**
*
* **************************
* Snippet: PrevJumpNextXHTML
* By: Jeroen Bosch modded by OncleBen31 and modified again by PMS
* Date: Mar 2008
* version: 0.3 (based on the PrevJumpNext v0.3)
* **************************
*
* Function:
* Generates buttons to navigate between document of a same directory.
* Very handy on top or bottom of each individual newspost/log item
* Highly configurable. It can display :
* - 'Prev' and 'Next' button with or without document titles
* - 'first' and 'last' document.
* - 'Index' link to parent folder
* - a DropList to jump quickly to a document
*
* You can use a classic use of the snippet or use the paginate option
* which allow you to use PlaceHolders to personnalise your navigation
* buttons :
* - [+PJN_first+] : the first document
* - [+PJN_prev+] : the previous document
* - [+PJN_jump+] : the droplist to jump to the selectionned document
* - [+PJN_index+] : the link to retern to the index page
* - [+PJN_next+] : the next document
* - [+PJN_last+] : the last document
*
* There is many option which can allow you to sort the document, set
* the text to use with the element, etc ... :
* - sortBy : Sort items by? 'menuindex' or 'id' or 'createdon', etc... (default createdon)
* - sortHow : Sort items How? 'ASC' or 'DESC' (default ASC)
* - displayTitle : how 'prev' and 'next' or display document titles (default true)
* - displayFixed : Show 'first' and 'last' (default false)
* - usePlaceHolder : Set at true to use PlaceHolder : [+PJN_first+] , [+PJN_prev+] , [+PJN_jump+] , [+PJN_index+] , [+PJN_next+] , [+PJN_index+] (default false)
* - useJump : Replace the Index link by the Jump dropList when NOT using the PlaceHolders (default false)
* - indexDocumentID :Specifie the document to go using the link "index". (by default its is the parent ID)
* - displayNoPrevNext : set to true to display a text when there is no Prev or no Next element (default false)
* - noPrevNextText : Text to display if there is no Prev or no Next element :(default "-")
* - indexText : Text to use with the link "index" (default "Index")
* - jumpText : Text to use with the dropdown list (jump function) (default :"Please Select")
* - firstText : Text to use with the link "First" (default "<< First")
* - prevText : Text to use with the link "Prev" when $displayTitle is set to false (default "< Prev")
* - nextText : Text to use with the link "Next" when $displayTitle is set to false (default "Next >")
* - lastText : Text to use with the link "Last" (default "Last >>")
*
*
* The output use <div> and <span> to allow you to CSS the buttons
*
*
* Enjoy and don't esitate to ask new features
* Exemples :
*
* [[PrevNext? sortBy=menuindex &sortHow=ASC &displayTitle=true]]
* Or
* [[PrevJumpNext_New? &sortBy=`pub_date` &usePlaceHolder=true &indexDocumentID=`84` &firstText=`Première` &lastText=`Dernière` &prevText=`Précédente` &nextText=`Suivante` &indexText=`Liste des News` &jumpText=`Accès rapide` &displayNoPrevNext=true &noPrevNextText=`C'est le bout`]]
* with this place holder in the document [+PJN_first+] [+PJN_prev+] [+PJN_jump+] [+PJN_index+] [+PJN_next+] [+PJN_last+]
*/
/* TODO
- Limiter la longeur de la liste
- Ajouter la phrase article n° X sur Total
- Faire la traduction
- Ajouter un préfix lors de l'utilisation des titres pour Prev et Next
*/
# Settings
# Sort items by? 'menuindex' or 'id' or 'createdon'
if(!isset($sortBy))
{
$sortBy = 'createdon'; // default in NewsListing-snippet
}
# Sort items How? 'ASC' or 'DESC'
if(!isset($sortHow))
{
$sortHow = 'ASC'; // default in NewsListing-snippet
}
# Show 'prev' and 'next' or display document titles?
if(!isset($displayTitle))
{
$displayTitle = true;
}
# Show 'first' and 'last'
if(!isset($displayFixed))
{
$displayFixed = false;
}
// Parameters added By OncleBen31
# Set at true to use PlaceHolder : [+PJN_first+] , [+PJN_prev+] , [+PJN_jump+] , [+PJN_index+] , [+PJN_next+] , [+PJN_index+]
if(!isset($usePlaceHolder))
{
$usePlaceHolder = false;
}
# Replace the Index link by the Jump dropList when NOT using the PlaceHolders
if(!isset($useJump))
{
$useJump=false;
}
# Specifie the document to go using the link "index". (by default its is the parent ID)
if(!isset($indexDocumentID))
{
$indexDocumentID=$modx->documentObject['parent'];
}
# set to true to display a text when there is no Prev or no Next element
if(!isset($displayNoPrevNext))
{
$displayNoPrevNext=false;
}
# Text to display if there is no Prev or no Next element
if(!isset($noPrevNextText))
{
$noPrevNextText="-";
}
# Text to use with the link "index"
if(!isset($indexText))
{
$indexText="Index";
}
# Text to use with the dropdown list jump function
if(!isset($jumpText))
{
$jumpText="Please Select";
}
# Text to use with the link "First"
if(!isset($firstText))
{
$firstText="<< First";
}
# Text to use with the link "Prev" when $displayTitle is set to false
if(!isset($prevText))
{
$prevText="< Prev";
}
# Text to use with the link "Next" when $displayTitle is set to false
if(!isset($nextText))
{
$nextText="Next >";
}
# Text to use with the link "Lastt"
if(!isset($lastText))
{
$lastText="Last >>";
}
//
// The code:
//
// Get the parent ID
$parentid = $modx->documentObject['parent']; // maybe this solves it all, but I'm not sure.
// (re)set the $id variable to the one of this document.
$id = $modx->documentIdentifier;
// select the other members in this folder -- See: NOTE 1
$fields='id,pagetitle,isfolder'; // what fields do you want to know
$children = $etomite->getActiveChildren($parentid, $sortBy, $sortHow, $fields);
// the number of selected documents
//$limit = $modx->recordCount($children);
$limit = count($children);
// set $y to zero
$y = 1;
// sorting the documents, giving them a sequential and searchable index
foreach ($children as $child)
{
$my_array[$y] = $child;
if ($my_array[$y]['id']==$id)
{
$current=$y; // The current page has number $y in the array
}
$y++;
}
$prev = $current-1;
$next = $current+1;
// ### Construction oh the elements
// First item
$PJN_firsPlaceHolder =
'<a href="[~'
. $my_array[1]['id']
. '~]">'
. $firstText
. '</a>';
// Prev item
if($prev > 0 && !$displayTitle )
{
$PJN_prevPlaceHolder =
'<a href="[~'
. $my_array[$prev]['id']
. '~]">'
. $prevText
. '</a>';
}
elseif($prev > 0 && $displayTitle)
{
$PJN_prevPlaceHolder =
'<a href="[~'
. $my_array[$prev]['id']
. '~]">'
. $my_array[$prev]['pagetitle']
. '</a>';
}
elseif($prev <= 0 && $displayNoPrevNext)
{
$PJN_prevPlaceHolder = $noPrevNextText;
}
// Jump item
$PJN_jumpPlaceHolder =
'<form action="" name="jump1" style="display:inline;">'
. '<select name="myjumpbox" onchange="javascript:if (this.selectedIndex != 0) {var ops=this.getElementsByTagName(\'option\'); var url=ops[this.selectedIndex].getAttribute(\'value\'); if (url) {location.href=url;};}">'
. '<option selected="selected">'
. $jumpText
. '</option>';
foreach ($my_array as $my_page)
{
$PJN_jumpPlaceHolder .=
'<option value="[~'
. $my_page['id']
. '~]" >'
. $my_page['pagetitle']
. '</option>';
}
$PJN_jumpPlaceHolder .= '</select></form>';
// Index item
$PJN_indexPlaceHolder =
'<a href="[~'
. $indexDocumentID
. '~]">'
. $indexText
. '</a>';
// Next item
if($next <= $limit && !$displayTitle)
{
$PJN_nextPlaceHolder =
'<a href="[~'
. $my_array[$next]['id']
. '~]">'
. $nextText
. '</a>';
}
elseif($next <= $limit && $displayTitle)
{
$PJN_nextPlaceHolder =
'<a href="[~'
. $my_array[$next]['id']
. '~]">'
. $my_array[$next]['pagetitle']
. '</a>';
}
elseif($next > $limit && $displayNoPrevNext)
{
$PJN_nextPlaceHolder = $noPrevNextText;
}
// Last item
$PJN_lastPlaceHolder =
'<a href="[~'
. $my_array[$limit]['id']
. '~]">'
. $lastText
. '</a>';
// #### Output commputing modded by Oncleben31
if (!$usePlaceHolder)
{
// Here starts the output
$output = '';
$output .= '<div class="PJN_Menu">';
if($displayFixed)
{
$output .=
$PJN_firsPlaceHolder
. ' < ';
}
$output .=
$PJN_prevPlaceHolder
. ' | ';
if($useJump)
{
$output .=
$PJN_jumpPlaceHolder
. ' | ';
}
else
{
$output .=
$PJN_indexPlaceHolder
. ' | ';
}
$output .= $PJN_nextPlaceHolder;
if($displayFixed)
{
$output .=
' > '
. $PJN_lastPlaceHolder;
}
$output .= '</div>';
return $output;
}
else
{
// Set PlaceHolder
$modx->setPlaceholder(
'PJN_first'
, '<span class="PJN_Menu"><span class="PJN_First">'
. $PJN_firsPlaceHolder
. '</span></span>'
);
$modx->setPlaceholder(
'PJN_prev'
, '<span class="PJN_Menu"><span class="PJN_Prev">'
. $PJN_prevPlaceHolder
. '</span></span>'
);
$modx->setPlaceholder(
'PJN_jump'
, '<span class="PJN_Menu"><span class="PJN_Jump">'
. $PJN_jumpPlaceHolder
. '</span></span>'
);
$modx->setPlaceholder(
'PJN_index'
, '<span class="PJN_Menu"><span class="PJN_Indext">'
. $PJN_indexPlaceHolder
. '</span></span>'
);
$modx->setPlaceholder(
'PJN_next'
, '<span class="PJN_Menu"><span class="PJN_Next">'
. $PJN_nextPlaceHolder
. '</span></span>'
);
$modx->setPlaceholder(
'PJN_last'
, '<span class="PJN_Menu"><span class="PJN_Last">'
. $PJN_lastPlaceHolder
. '</span></span>'
);
}
?>gracedman: I see in the code that the isFolder field info is available. With this you could know if a document is a parent (isFolder) or not. So you could add an if statement in the logic and go to the sub (children) in this instance. I would need to think a bit more than I am able to right now to get into more details but I think that is the direction to look.
Quote
isfolder - [0|1] Whether or not the document is a folder.
First you need to get your self into the children level. But remember that you need to get back to the parent level as well and you have to be able to set a limit so that it doesn’t go all the way back to the home page (unless that is what you want).
includeFolders : Boolean : include folder documents in the menu (default true);Will the menu now drill down into folders including the children in the menu? I have seen a request for this feature before.