Jump to content

Check the pageNum of the parent page - possible?


doolak
 Share

Recommended Posts

Hi there,

as the title says I am trying to check the pageNum of a parent page - something like:

$page->parent->pageNum (wich does not work)

Any idea if and how one could do this?

Cheers, Christian

Link to comment
Share on other sites

I am not sure how a parent page can have a current page number. $page->pageNum will get you the page number of the current page. Perhaps you want the number of pages that would be generated when rendering the parent of the current page?

Can you explain your structure and needs in a little more detail?

Link to comment
Share on other sites

The problem is as follows:

There are lots of galleries, on every page there are just 12 displayed (with pagination).

If someone was visiting e.g. page 4 of the paginated gallery pages and chooses one gallery to view - he should have the option to go back to the gallery overview, but to page 4 of this, not to the first page.

E.g.:

The visitor was on http://www.xyz.de/galerie/page3 and watched one of the shown galleries

When klicking "back to the overview" he should get back to http://www.xyz.de/galerie/page3 - not to http://www.xyz.de/galerie/

Link to comment
Share on other sites

Makes sense. So you need to somehow capture the page number the users comes from. Not sure how your are linking the user to watch a gallery, but you could append the page number as a GET variable to the link to the gallery so that the back to the overview link includes the page number.

Does that sound ok?

Link to comment
Share on other sites

@doolak You may try this. I took my code and modified it a little so it may not work out of the box.

//parent of your galaries
$galleryHome = $page->parent;
//all your published gallery pages (make sure you use the same sort option as in your template when output)
$galleries = $galleryHome->children;
//page being viewed
$currentPage = $page;
//number of galleries per page
$galleriesPerPage = 5;
//index of the page in array
$PageIdInArray=NULL;

//the number of the page your current gallery belongs
$pageNum=0;
foreach($galleries as $i => $p) {
    //iterate every galleriesPerPage time
    if (($i%$galleriesPerPage)==0) {
        $pageNum++;
    }
    //
    if ($currentPage->id == $p->id) {
        $PageIdInArray = $i;
        break;
    }
}
//if we found our page in array and $pageNum<>0
if ($PageIdInArray && $pageNum) {
    //construct url to the galleris landing page
    $url = $galleryHome->url . "page" . $pageNum;
    echo "<a url='$url'>Back to galleries</a>";
}
 
  • Like 3
Link to comment
Share on other sites

Why not use on every overview-page:

$session->set('lastOverviewPage', $page->url);

and on every gallery page:

echo '<a href="' . $session->get('lastOverviewPage') . '">go back to overview</a>';

?

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Why not use on every overview-page:

$session->set('lastOverviewPage', $page->url);

and on every gallery page:

echo '<a href="' . $session->get('lastOverviewPage') . '">go back to overview</a>';

?

It can work and is clean and simple. But it's not working if the user enters directly the image and not the gallery.  ;)

Thank you slkwrm!

url should href of course but thank you anyways it's working like a charm!  ^_^

EDIT:

so 

echo "<a url='$url'>Back to galleries</a>";

should be

echo "<a href='$url'>Back to galleries</a>";
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...