Dec 04, 2008, 12:12 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Adding Next and Previous Links  (Read 4668 times)
0 Members and 1 Guest are viewing this topic.
moondog
Jr. Member
*
Posts: 7


« on: Jan 03, 2006, 07:01 AM »

Hi all,

Is it possible to add links to navigate through blog entries? I would like to modify the chunk that comes out the box named "FormBlogComments" from;

Quote
<p style="margin-top: 1em;font-weight:bold">Enter your comments in the space below (registered site users only):</p>

[!UserComments? &canpost=`Registered Users, Site Admins` &makefolder=`0` &postcss=`comment` &titlecss=`commentTitle` &numbercss=`commentNum` &altrowcss=`commentAlt` &authorcss=`commentAuthor` &ownercss=`commentMe` &sortorder=`0`!]

to;


<p style="margin-top: 1em;font-weight:bold">Enter your comments in the space below (registered site users only):</p>
Quote
[!UserComments? &canpost=`Registered Users, Site Admins` &makefolder=`0` &postcss=`comment` &titlecss=`commentTitle` &numbercss=`commentNum` &altrowcss=`commentAlt` &authorcss=`commentAuthor` &ownercss=`commentMe` &sortorder=`0`!]
<p> Next Article : Previous Article (with some logic to check if there is a now/next link to present to user?)

New to MODx and PHP!!

TIA
Logged
moondog
Jr. Member
*
Posts: 7


« Reply #1 on: Jan 03, 2006, 10:00 AM »

DOH!

Just noticed that NewsListing does this for me!! Getting the hang of this great CMS now!!

But - how can you isolate via the snippet to view just from ONE folder, and said articles that are contained in that folder ONLY?

Using this code;

Quote
[!NewsListing? &amp;startID=`42` &amp;summarize=`3` &amp;paginate=`1` &amp;alwaysshow=`1`!]<br /><br />Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles<br />[+previous+] [+pages+] [+next+] <div>&nbsp;</div>

Where the folder i've called News has a value of 42 in the () next to the folder icon in the Manager?
Logged
Mark
Coding Team
*
Posts: 3,247


Ditto Developer


WWW
« Reply #2 on: Jan 03, 2006, 02:04 PM »

Quote
Is it possible to add links to navigate through blog entries?

There are many snippets that do that including this one:

Code:
//
// **************************
// Snippet: PrevNext
// By: Jeroen Bosch
// Date: februari 2005
// version: 0.9
// **************************
//
// Function:
// Generates a simple previous and next button. very
// handy on top or bottom of each individual newspost/log item
// Highly configurable. It can display document titles
// and add 'first' and 'last' to the options.
//
// You can set every option with the snippet call.
// example:

// [[PrevNext?sortBy=menuindex&sortHow=ASC&displayTitle=true]]


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

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

// Here starts the output
$output = "";
$output .= "<div class='PrevNextMenu'><div>";

if($displayFixed==true) {
    $output .= "&lt; <a href='[~".$my_array[1]['id']."~]'>first</a> ‌ ";
} else {
    $output .= "&lt; ";
}

if($prev > 0 && $displayTitle==false){
    $output .= " <a href='[~".$my_array[$prev]['id']."~]'>prev</a> ";
} elseif($prev > 0 && $displayTitle==true) {
    $output .= " <a href='[~".$my_array[$prev]['id']."~]'>".$my_array[$prev]['pagetitle']."</a> ";
}

$output .= "‌ <a href='[~".$parentid."~]'> index </a> ‌";

if($next <= $limit && $displayTitle==false){
    $output .= " <a href='[~".$my_array[$next]['id']."~]'>next</a> ";
} elseif($next <= $limit && $displayTitle==true) {
    $output .=" <a href='[~".$my_array[$next]['id']."~]'>".$my_array[$next]['pagetitle']."</a> ";
}

if($displayFixed==true) {
    $output .= " ‌ <a href='[~".$my_array[$limit]['id']."~]'>last</a> >";
} else {
    $output .= " &gt;";
}

$output .= "</div></div><br />";
$output .= "";

return $output;
Logged

moondog
Jr. Member
*
Posts: 7


« Reply #3 on: Jan 04, 2006, 03:35 AM »

Mark,

Thank you very much for the reply and snippet - that works a treat for pagination of the articles.

Except calling it this way;

[[PrevNext?displayTitle=false&displayFixed=true]]

Is still showing the document titles and not just prev/next?

Also this is driving me mad still,as I am still wondering how you can via the NewsListing snippet isolate to read from ONE folder, and said articles that are contained in that folder ONLY?

Every call I make using the NewsListing snippet seems to call all folders that came with the default install of Modx.

TIA.
« Last Edit: Jan 04, 2006, 04:22 AM by moondog » Logged
Mark
Coding Team
*
Posts: 3,247


Ditto Developer


WWW
« Reply #4 on: Jan 04, 2006, 10:20 AM »

&startID=`idoffolderwithchildren`
Logged

moondog
Jr. Member
*
Posts: 7


« Reply #5 on: Jan 04, 2006, 11:04 AM »

Mark,

Thanks very much for all your help.

Works like a charm now Smiley
Logged
OncleBen31
Sr. Member
****
Posts: 283


I believe in MODx!


WWW
« Reply #6 on: Apr 13, 2006, 04:10 PM »

I've made some modification to the PrevNext snippet to replace the index link by a dropdown list to the other document of the folder. I call it PrevJumpNext

I hope this can help someone. I think it can be improved by option to add the parent link in the droptdown list or to use a CCS dropdown replacing the form one.

Code:
//
// **************************
// Snippet: PrevJumpNext
// By: Jeroen Bosch moded by OncleBen31
// Date: februari 2005
// version: 0.9
// **************************
//
// Function:
// Generates a simple previous and next button. very
// handy on top or bottom of each individual newspost/log item
// Highly configurable. It can display document titles
// and add 'first' and 'last' to the options.
//
// You can set every option with the snippet call.
// example:

// [[PrevNext?sortBy=menuindex&sortHow=ASC&displayTitle=true]]


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

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

// Here starts the output
$output = "";
$output .= "<div class='PrevNextMenu'><div>";

if($displayFixed==true) {
    $output .= "&lt; <a href='[~".$my_array[1]['id']."~]'>first</a> ‌ ";
} else {
    $output .= "&lt; ";
}

if($prev > 0 && $displayTitle==false){
    $output .= " <a href='[~".$my_array[$prev]['id']."~]'>prev</a> ";
} elseif($prev > 0 && $displayTitle==true) {
    $output .= " <a href='[~".$my_array[$prev]['id']."~]'>".$my_array[$prev]['pagetitle']."</a> ";
}

$output .= '‌ <form action="" name="jump1" style="display:inline;">
<select name="myjumpbox"
 OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value">
     <option selected>Please Select...';
foreach ($my_array as $my_page) {
//      $output .= '    <option value="'[~'.$my_page['id'].'~]">'.$my_page['title'];
     $output .= '    <option value="[~'.$my_page['id'].'~]">'.$my_page['pagetitle'];

}
$output .= '</select></form> ‌';

if($next <= $limit && $displayTitle==false){
    $output .= " <a href='[~".$my_array[$next]['id']."~]'>next</a> ";
} elseif($next <= $limit && $displayTitle==true) {
    $output .=" <a href='[~".$my_array[$next]['id']."~]'>".$my_array[$next]['pagetitle']."</a> ";
}

if($displayFixed==true) {
    $output .= " ‌ <a href='[~".$my_array[$limit]['id']."~]'>last</a> >";
} else {
    $output .= " &gt;";
}

$output .= "</div></div><br />";
$output .= "";

return $output;
Logged
Mark
Coding Team
*
Posts: 3,247


Ditto Developer


WWW
« Reply #7 on: Apr 28, 2006, 02:23 PM »

Very cool! Can you please put this new snippet in its own thread and make the snippet a .txt download? Thanks!
Logged

OncleBen31
Sr. Member
****
Posts: 283


I believe in MODx!


WWW
« Reply #8 on: Apr 28, 2006, 04:18 PM »

I want to do some modification, like using placeholder. I will post it when I achieved it.
Logged
OncleBen31
Sr. Member
****
Posts: 283


I believe in MODx!


WWW
« Reply #9 on: May 02, 2006, 04:12 AM »

I've created a new topic dedicated to PrevJumpNext snippet :
http://modxcms.com/forums/index.php/topic,4300.msg31245.html#msg31245
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!