Jump to content

How to find all normal public pages — only those we'd want in sitemap.xml


alan
 Share

Recommended Posts

A couple of times I've thought "It would be good if I could get from the API directly all of the publicly visible pages and nothing more, or use the API to build an array that I could subsequently look in that held this set". That set of pages would be those we would want, for example, Google to know about and so would not include the login page or pages like

example.com/pw/repeaters/for-field-123/for-page-1456/

In pseudo code one way I could see doing it would be:

foreach(section-is-part-of-nav) {
foreach(page-in-section-is-part-of-nav) {
	visible-pages-array[store-this-page-id]
}
}

Two uses I can think of are to help when building a sitemap.xml file (I've not yet looked at the sitemap.php template that ships with PW, shame on me if that solves all of this) and the other use is for allowing short-links to work, but only for normal, public pages.

Any thoughts on how this can be done will be received with great interest :)

PS: What's the betting this can likely be done directly with the API and I've missed something simple and obvious...

Link to comment
Share on other sites

Soma, I totally forgot! WHAT am I like... And I had your module bookmarked from the start and watch the thread too as it's something I am sure I will need.

Thanks for the suggestion, I'll check it for use in solving this, cheers!

Link to comment
Share on other sites

OK, the solution "I've" come up with (err, Soma and Ryan came up with ;)) is a hybrid of some of Soma's code and Ryan's:

if($page->id == 1232 && $id = (int) $input->urlSegment1) { // 1232 is a page with the URL /p/
   $redirect = $pages->get("id=$id");
   if($redirect->id && $redirect->viewable()) {
    $session->redirect($redirect->url);
   } else {
    //throw new Wire404Exception();
    $session->redirect($pages->get($config->http404PageID)->url);
   }
}

This is now complete and solves the short-links referred to in the opening post of this thread. I might see if I can make this into a Module. I don't know if it is a good candidate for being a Module and I don't know if I will be able to work out how to do it and I don't know when I'll get to try (just a few don't know's then ;)) but maybe I'll do it!

Meantime, thanks again to everyone who commented, cheers, -Alan

  • 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...