Post by jeeremie » Sat Nov 10, 2007 1:55 am

Hello,

I want to change the "Result Pages: 1 of 3" with some links PREVIOUS/NEXT to navigate through the products pages or something like this: "Pages: [1] 2 3 4 ... 8".

Is it possible? (Actually, I would like to have both).

No one sees and click on the "Result Pages: 1 of 3" to change to next page.

User avatar
Newbie

Posts

Joined
Sat Jul 28, 2007 8:46 pm


Post by ogun » Sat Nov 10, 2007 4:00 am

I'll need to do the same thing. Thought for a moment that it just meant editing the 'select' into a 'ul' in category.tpl - but it looks like it's only accepting pagination stuff from $_post? that can't be right.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by beata » Sun Nov 11, 2007 9:25 am

You have to change two files and create a new file.

Step1:
Create a new file in your {template}/content directory.
Copy and paste the following code to the new file and name it with _pagination.tpl

Code: Select all

<div class="pagination">
  <?php foreach ($pages as $p): ?>
  <?php if ($p['value'] == $page): ?>
  <a href="<?php echo $p['href']?>" class="active"><?php echo $p['value']?></a>
  <?php else: ?>
  <a href="<?php echo $p['href']?>"><?php echo $p['value']?></a>
  <?php endif; ?>
  <?php endforeach; ?>
</div>
Step2:
Editing catalog/template/default/content/category.tpl

Step 2-1:
Rename the variable name ($pages) in the loop, so that we can use the original $pages later in our _pagination.tpl

Code: Select all

// FIND
        <?php foreach ($pages as $pages) { ?>
        <?php if ($pages['value'] == $page) { ?>
        <option value="<?php echo $pages['value']; ?>" SELECTED><?php echo $pages['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $pages['value']; ?>"><?php echo $pages['text']; ?></option>
        <?php } ?>
        <?php } ?>

// REPLACE WITH 
       <?php foreach ($pages as $p) { ?>
        <?php if ($p['value'] == $page) { ?>
        <option value="<?php echo $p['value']; ?>" SELECTED><?php echo $p['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $p['value']; ?>"><?php echo $p['text']; ?></option>
        <?php } ?>
        <?php } ?>
Step 2-2:
Place the following code in which place you want to display.

Code: Select all

<?php include_once '_pagination.tpl'; ?>

Step 3:
Edit catalog/controller/category.php


Step 3-1:
Find $page_data[] and add the url for page link.

Code: Select all

<?php

$page_data[] = array(
	'text'  => $language->get('text_pages', $i, $database->getPages()),
	'value' => $i,
	// Add url for page link
	'href'  => $url->href('category', 'page', array(
		'path' => $request->get('path'),
		'page'  => $i
	))
	// Add url for page link -- END
);

?>

Step 3-2:
Find function page()

Code: Select all

<?php

	function page() {
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$session  =& $this->locator->get('session');
		$url      =& $this->locator->get('url');

		/* Comment out these code
		if ($request->has('page', 'post')) {
                       $session->set(($request->has('path') ? 'category.' . $request->get('path') . '.page' : 'category.page'), $request->get('page', 'post'));
		}
		*/

		// Add $_GET support
		$page = $request->get('page');
		if (!$page) {
			$page = $request->get('page', 'post');
		}
		if ($page) {
			$session->set(($request->has('path') ? 'category.' . $request->get('path') . '.page' : 'category.page'), $page);
		}
		// Add $_GET support -- END

		$response->redirect($url->ssl('category', FALSE, array('path' => $request->get('path'))));
	}

?>

Good Luck! ;)
Last edited by beata on Sun Nov 11, 2007 10:47 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Nov 01, 2007 8:41 pm

Post by ogun » Mon Nov 12, 2007 1:27 am

nice one beata :)

hope this makes it into the official distribution. don't like the idea of having to rely on javascript or adding a form button just to change pages.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by jeeremie » Mon Nov 12, 2007 1:30 am

Thanks Beata,

That's working  though I didn't know to follow your steps.

Here is what I have done:

First I have created the _pagination.tpl page:

Code: Select all

<div class="paginate">
    Pages: 
    <?php foreach ($pages as $p): ?>
    <?php if ($p['value'] == $page): ?>
    <a class="active" href="<?php echo $p['href']?>">[<?php echo $p['value']?>]</a>
    <?php else: ?>
    <a href="<?php echo $p['href']?>"><u><?php echo $p['value']?></u></a>
    <?php endif; ?>
    <?php endforeach; ?>
</div>
And in category.tpl:

Code: Select all

  <div class="results">
    <div class="left"><?php echo $text_results; ?></div>
    <div class="right"><?php include '_paginate.tpl'; ?></div>
  </div>
No need to do more. It works well.

By the way, if I try to change the code in category.php I get an error so I didn't try.

Thanks again.
Last edited by jeeremie on Mon Nov 12, 2007 1:33 am, edited 1 time in total.

User avatar
Newbie

Posts

Joined
Sat Jul 28, 2007 8:46 pm


Post by beata » Mon Nov 12, 2007 2:36 am

Sorry, my friend told me I should use 'pagination' instead of 'paginate'
So I have changed 'paginate' into 'pagination'.

in _pagination.tpl

Code: Select all

<div class="paginate"> // let it be 'pagination'
in category.tpl

Code: Select all

<?php include '_paginate.tpl'; ?> // same as above, change the include path into '_pagination.tpl'
jeeremie wrote: By the way, if I try to change the code in category.php I get an error so I didn't try.
Can you provide the error message?

And... I didn't try this code in any other version of opencart 0.7.7
Last edited by beata on Mon Nov 12, 2007 2:42 am, edited 1 time in total.

Newbie

Posts

Joined
Thu Nov 01, 2007 8:41 pm

Post by jeeremie » Mon Nov 12, 2007 2:49 am

I get this error:
Fatal error: Call to undefined method language::get() in /home/webkreat/public_html/hailstormdesign/catalog/plugin/category.php on line 43

It  occurs when I add this code in category.php:

Code: Select all

<?php 
$page_data[] = array(
	'text'  => $language->get('text_pages', $i, $database->getPages()),
	'value' => $i,
	// Add url for page link
	'href'  => $url->href('category', 'page', array(
		'path' => $request->get('path'),
		'page'  => $i
	))
	// Add url for page link -- END
);
?>
I think I have version 0.9 but i am not sure. How do I know my version?

User avatar
Newbie

Posts

Joined
Sat Jul 28, 2007 8:46 pm


Post by beata » Mon Nov 12, 2007 6:07 am

jeeremie wrote: I get this error:
Fatal error: Call to undefined method language::get() in /home/webkreat/public_html/hailstormdesign/catalog/plugin/category.php on line 43

I think I have version 0.9 but i am not sure. How do I know my version?
Wow.. you got a future version of opencart!! (The current release is 0.7.7)
Actually, I can't get any version information from source code either. :-\

Newbie

Posts

Joined
Thu Nov 01, 2007 8:41 pm

Post by thedotmack » Wed Jun 18, 2008 9:57 am

anyone know what the steps would be to get this working for paginating the search results?

Newbie

Posts

Joined
Sun Jun 01, 2008 11:02 am

Post by bruce » Wed Jun 18, 2008 10:09 am

You might also like to look here for a similar discussion and working example.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 2 guests