Jump to content
alan

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

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

Share this post


Link to post
Share on other sites

Thanks diogo, that looks very useful and it may allow me to solve the more general thing I was looking for (find all pages suitable for public consumption).

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...