Welcome, Guest. Please login or register.
Did you miss your activation email?
23 Jul 2008, 14:06

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1]
Print
Author Topic: Pagination for news articles.  (Read 2438 times)
0 Members and 1 Guest are viewing this topic.
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« on: 17 Jun 2007, 23:36 »

Hi everyone,

I need help simplifying in the pagination for news articles.

I using the system that can be found (with instructions) at http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm.

Its all done in javascript, but you don't need to know javascript to use it. To get this working, I need people who know HTML and PHP (mainly PHP).

This javascript pagination system can be easily adapted into CMSMS, but when creating news articles, it hard.
I want to create user defined tags in order to make it much more simpler for those editors who don't understand programming.
For the development, we will user Demo 5, which is the one with the drop down box.

All of the pages in the article need to be split up with <div> tags. So instaed of getting editors to put:
<div class="virtualpage5">
...
</div> to separate pages.

Will can make UDT.

{spage}    //s is for start
echo "<div class=\"virtualpage5\">";

{epage}  //e is for end
echo "</div>";

I was planing on using {page} and {/page} like the if statement, but I got errors because / is an invalid character, does anyone know away around this?

At the end of each page, we need to add the following code:

<!-- Pagination DIV for Demo 5 -->
<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>

<!-- Initialize Demo 5 -->
<script type="text/javascript">
var gallery=new virtualpaginate("virtualpage5", 1)
gallery.buildpagination("galleryselect", ["castle", "park", "harvest", "country"])
</script>

In the <!-- Initialize Demo 5 --> there is the line
gallery.buildpagination("galleryselect", ["castle", "park", "harvest", "country"])

castle, park, harvest, country, all represent the values for each page, these appear in the drop down box aswell.

Firstly, instead of adding that to the bottom of the page, will put it in a UDT, we will call it pagination.

So that works all fine. But we obviously don't want every article to have 4 pages called caste, park, harvest and country do we. We can use the $params['text here'] variable so that the editors can name their pages. So we can change it to:

gallery.buildpagination("galleryselect", [\"".$params['page1']."\", \"".$params['page2']\", \"".$params[page3']\", \"".$params['page4']."\"])

Well thats all plan and simple, isn't it. Now all the edit has to do for an arictle is type:

{spage}

Page 1

{epage}

{spage}

Page 2

{epage}

{spage}

Page 3

{epage}

{spage}

Page 4

{epage}

{pagination page1="Page 1" page2="Page 2" page3="Page 3" page4="Page 4"} //that will automatically fill the javascript section.

But now for the tricky part...
What if the article had 7 pages? That would mean the editor would have to edit the UDT, and change that javascript line, everytime he want to make a new article that was different length to the last. Yes, this is where I got stuck and now need help.

We need it to automatically count the number of pages the user has created. Anyone can do that, just add $i++ to {spage}.
But for every page, me need to make a new variable, and then output that into the javascript section, with the valid syntax.

How do we get it to do this, that I don't not know, and I now need help from a more advanced programmer.


Cheers,
Cobby

Sorry for the unorganized post, but I found it difficult to explain my question.


Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 104
Offline Offline

Posts: 2413

Location: Ferrara, Italy


My kids


« Reply #1 on: 18 Jun 2007, 03:50 »

I need help simplifying in the pagination for news articles.
........

Look News SVN version for pagination

Alby
Logged

HOLIDAY:   15 July - 31 July

Member CMSMS Support Team
Italian Forum Moderator - Italian admin Project

Plugins: Geolocate hostip - Multiple random image - Image rotator (test beta) - Content Pagination

Modules: ForumMadeSimple - Howto (FMS)

Multilingual: CMSMS MLE 1.3.1 - Doc/Howto/Tips (#10)
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #2 on: 18 Jun 2007, 23:56 »

I need help simplifying in the pagination for news articles.
........

Look News SVN version for pagination

Alby

Could you ellaborate a little more.

I know there was pagination add for the list of news articles. But I want to make pages for the contents of the articles.

Cheers,
Cobby
Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 104
Offline Offline

Posts: 2413

Location: Ferrara, Italy


My kids


« Reply #3 on: 19 Jun 2007, 05:47 »

Could you ellaborate a little more.

I know there was pagination add for the list of news articles. But I want to make pages for the contents of the articles.

Ok, my mistake, I don't read  Lips sealed

However your method would to work with any content and not news content only.

My idea (but only idea very very very .... UNTESTED):
Use function block and {page name="XXXX"}{/page} tag:

Quote
function smarty_block_page($params, $content, &$smarty, &$repeat)
{
    if(!$repeat){
        if (isset($content)) {
            if (! isset($smarty->endpagination)) {
                $smarty->endpagination = 'gallery.buildpagination("galleryselect"; [';
            }

            $smarty->endpagination .= '"'. $params['name'] .'"';
            $smarty->assign('endpagination', $smarty->endpagination .']');

            // do some intelligent thing here with $content
            return $content;
        }
    }
}


Quote
{page name=Page1}
Page 1
{/page}

{page name=Page2}
Page 2
{/page}

{page name=Page3}
Page 3
{/page}

{page name=Page4}
Page 4
{/page}

<script type="text/javascript">
var gallery=new virtualpaginate("virtualpage5", 1)
{$endpagination}
</script>
Logged

HOLIDAY:   15 July - 31 July

Member CMSMS Support Team
Italian Forum Moderator - Italian admin Project

Plugins: Geolocate hostip - Multiple random image - Image rotator (test beta) - Content Pagination

Modules: ForumMadeSimple - Howto (FMS)

Multilingual: CMSMS MLE 1.3.1 - Doc/Howto/Tips (#10)
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #4 on: 20 Jun 2007, 22:16 »

Well I decided to go against your function idea, mainly because I am still a novice, and I don't understand some of the code.

But I am so close. The only problem I am having now, is when you put {pagination page1="PG 1"....}

It output nothing.

In {sp} (opens the <div>) I have a counted.

And this is the code for {paignation}
Code:
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = '1';


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [";


while($i<$p){
echo "\"".$params['page$i']."\", ";
$i++;
}
echo "])
</script>";

With that code it didn't work, the option in the drop down bow where simply blank. So I did a little problem solving. I adjusted {pagination} to this:
Code:
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = '1';

while($i<$p){                                        ///Add a second, yet identical, while loop outside the javascript
echo "\"".$params['page$i']."\", ";
$i++;
}

echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [";


while($i<$p){
echo "\"".$params['page$i']."\", ";
$i++;
}
echo "])
</script>";

And long behold, it is in fact just outputting "", "", "", .
So I know I am just doing something wrong with the $params stuff.

Can anyone see what I am doing wrong?

I also modified that second loop I add to:
Code:
while($i<$p){                                       
echo "\"\$params['page$i']\", ";
$i++;
}
And it outputted "$params['page1']", "$params['page2']", "$params['page3']",
So I know it is being told the correct page numbers.

So how do I rectify this $params problem?

Cheers,
Cobby
Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 104
Offline Offline

Posts: 2413

Location: Ferrara, Italy


My kids


« Reply #5 on: 21 Jun 2007, 03:29 »

Well I decided to go against your function idea, mainly because I am still a novice, and I don't understand some of the code.

But I am so close. The only problem I am having now, is when you put {pagination page1="PG 1"....}

It output nothing.

In {sp} (opens the <div>) I have a counted.

And this is the code for {paignation}
Code:
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = '1';


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [";


while($i<$p){
echo "\"".$params['page$i']."\", ";
$i++;
}
echo "])
</script>";

With that code it didn't work, the option in the drop down bow where simply blank. So I did a little problem solving. I adjusted {pagination} to this:
Code:
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = '1';

while($i<$p){                                        ///Add a second, yet identical, while loop outside the javascript
echo "\"".$params['page$i']."\", ";
$i++;
}

echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [";


while($i<$p){
echo "\"".$params['page$i']."\", ";
$i++;
}
echo "])
</script>";

And long behold, it is in fact just outputting "", "", "", .
So I know I am just doing something wrong with the $params stuff.

Can anyone see what I am doing wrong?

I also modified that second loop I add to:
Code:
while($i<$p){                                       
echo "\"\$params['page$i']\", ";
$i++;
}
And it outputted "$params['page1']", "$params['page2']", "$params['page3']",
So I know it is being told the correct page numbers.

So how do I rectify this $params problem?


Try with:

Quote
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = 1;  // is a integer
$pages = '';

while($i<$p){
   $pages .= "\"".$params['page$i']."\", ";
   $i++;
}
$pages = substr($pages, 0, -1); // clean last comma


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [$pages])
</script>";

Alby
Logged

HOLIDAY:   15 July - 31 July

Member CMSMS Support Team
Italian Forum Moderator - Italian admin Project

Plugins: Geolocate hostip - Multiple random image - Image rotator (test beta) - Content Pagination

Modules: ForumMadeSimple - Howto (FMS)

Multilingual: CMSMS MLE 1.3.1 - Doc/Howto/Tips (#10)
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #6 on: 21 Jun 2007, 04:27 »

Try with:

Quote
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = 1;  // is a integer
$pages = '';

while($i<$p){
   $pages .= "\"".$params['page$i']."\", ";
   $i++;
}
$pages = substr($pages, 0, -1); // clean last comma


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [$pages])
</script>";

Alby

That didn't work Sad
But I have found out the problem. It does like have the $1 in $params['page$i']. I think having that it will then be {pagination page$i="P1"}

I don't know how to get around this though Sad

Your help is really appreciated though Smiley

Cheers,
Cobby
Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 104
Offline Offline

Posts: 2413

Location: Ferrara, Italy


My kids


« Reply #7 on: 21 Jun 2007, 04:38 »

Try with:

Quote
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = 1;  // is a integer
$pages = '';

while($i<$p){
   $pages .= "\"".$params['page$i']."\", ";
   $i++;
}
$pages = substr($pages, 0, -1); // clean last comma


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [$pages])
</script>";

Alby

That didn't work Sad
But I have found out the problem. It does like have the $1 in $params['page$i']. I think having that it will then be {pagination page$i="P1"}

I don't know how to get around this though Sad

Your help is really appreciated though Smiley

Sorry, my mistake, change to (for page$i):

Quote
$pages .= '"'. $params['page$'.$i] .'",';  // no space after comma
« Last Edit: 21 Jun 2007, 04:45 by alby » Logged

HOLIDAY:   15 July - 31 July

Member CMSMS Support Team
Italian Forum Moderator - Italian admin Project

Plugins: Geolocate hostip - Multiple random image - Image rotator (test beta) - Content Pagination

Modules: ForumMadeSimple - Howto (FMS)

Multilingual: CMSMS MLE 1.3.1 - Doc/Howto/Tips (#10)
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #8 on: 21 Jun 2007, 05:02 »

No sorry, my mistake, I meant to say it doesn't like to have the $i in $params['page$i'].

Few typos, sorry.

I think I need to store it in an array, then extract that array, so its final will be $params['page1'] instead of $params['page$i']. But I know how to do that either, but am currently working on it.
Logged
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #9 on: 21 Jun 2007, 05:09 »

Ah its getting so close!
I now have the $params working, just with a 3 page article, the drop down box will repeat the title for page 1 twice, then page 2 Sad
I guess its something with the loop, so I will investigate.

EDIT: Also, you forgot to add the echo $pages; in aswell Tongue

EDIT2: I did a little testing, I got it to echo $pages at the bottom of the script, and it displayed correctly, as it should:
"Page 1", "Page 2", "Page 3"
The correct syntax require between the square brackets in the line of javascript is as follows:

["Page 1", "Page 2", "Page 3"]

I thought it might have something to do with the last comma, si manually enter the details in to the javascript line myself as:
["Page 1", "Page 2", "Page 3", ]

And that didn't seem to bother it.

Here is what I have in for {pagination}
Code:
echo '<div id="galleryselect" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <select style="width: 120px"></select> <a href="#" rel="next">Next</a>
</div>';

global $page;
global $p;
$i = 1;


echo "<script type=\"text/javascript\">
var gallery=new virtualpaginate(\"virtualpage5\", 1)
gallery.buildpagination(\"galleryselect\", [";
$pages = '';

while($i<$p){
   $pages .= '"'.$params['page'.$i].'", ';
echo $pages;
   $i++;
}
$pages = substr($pages, 0, -2); // clean last comma

echo "])
</script>";
echo $pages; //second echo to see that it is outputting correctly

And here is what I am entering in the page:
{sp}This is page 1, the introduction.{ep}
{sp}This is page 2, the main body.{ep}
{sp}This is page 3, the conclusion.{ep}
{pagination page1="Page 1" page2="Page 2" page3="Page 3"}

And you can see the result at -> http://www.diycomputing.com.au/index.php?page=pagination

Cheers,
Cobby
« Last Edit: 21 Jun 2007, 05:27 by Cobby » Logged
Cobby
Forum Member
*

Karma: 0
Offline Offline

Posts: 23


« Reply #10 on: 01 Jul 2007, 04:45 »

I got it working! All is good now, thanks for your help alby. When my website is finished I will add it to the dev area for others to use.
Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 104
Offline Offline

Posts: 2413

Location: Ferrara, Italy


My kids


« Reply #11 on: 24 Sep 2007, 04:04 »

I got it working! All is good now, thanks for your help alby. When my website is finished I will add it to the dev area for others to use.

I have resumed the job on this in order to see to generalize it and apply ALL features.
I hope to publish it tomorrow for a test

Alby
Logged

HOLIDAY:   15 July - 31 July

Member CMSMS Support Team
Italian Forum Moderator - Italian admin Project

Plugins: Geolocate hostip - Multiple random image - Image rotator (test beta) - Content Pagination

Modules: ForumMadeSimple - Howto (FMS)

Multilingual: CMSMS MLE 1.3.1 - Doc/Howto/Tips (#10)
Pages: [1]
Print
Jump to: