Jump to content

Recommended Posts

Posted

Hello,

I am working on a website that has 4 domains. 3 are a alias to the main domain. I want to achieve the following.

Home - domain A

        Child 1 of Home - domain B

                   Child of child - domain B

                   Child of child - domain B

        Child 2 of Home - domain C

                   Child of child - domain C

                   Child of child - domain C

        Child 3 of Home - domain D

                   Child of child - domain D

                   Child of child - domain D

 

Basicly I made a website with a home and 3 onepager that contain different pages.

How can I achieve that if you go from home to "Child 1 of Home - domain B" the domain changes in the url?

Posted

This is possible with the Multi-site module. Read through the whole thread. There is valuable info in it. You may need the restructure your tree a bit.

  • Like 1
Posted

I looked at the multi-site module but was not sure I could do it with that. I will make a test setup.

Is something like this possible?

if($page->domain != this page url then force $page->url as domain

Basicly if the domain does not equel that of the field then load the page with the corresponding domain of $page->domain

Posted

It is solved finally. Used the multisite by @Soma

I did not find in the documentation that I had to add all domains also to site/config.php. When I did that, all worked like a charm.

  • Like 2
Posted

I did not find it in the topic. Probably missed it.

I you use a different domain to enter the admin you get an error. That was the hint to add them to the config.php...

  • 4 weeks later...
Posted

I have come across the following quirk.

I redirect a 404 to the search so that a 404 is never given but a list of relevant pages.

I just found out that this wil build an infinite loop.

A page in the rootdomain will show up, but will have the domain you are currently (on of the muli sites) on. But page doens't excist on that domain so you go through the search again and again...

Now I changed ->url to ->httpUrl but this doesn't take into account the orginal domain that page is from.

Is there a way around this?

Posted

I can also show the links on the 404 page. But how do I force the right domain for the search results in the list?

Posted
35 minutes ago, webhoes said:

A page in the rootdomain will show up, but will have the domain you are currently (on of the muli sites) on. But page doens't excist on that domain so you go through the search again and again...

Now I changed ->url to ->httpUrl but this doesn't take into account the orginal domain that page is from.

If you dont want to show pages from other domain roots, you can add has_parent to limit returned pages to one domain only

https://processwire.com/api/selectors/#finding2

Posted

Actually I do want that. It is ok if a page from another domain shows up in the list. But if you click on it, you should go to that page with the corresponding domain.

Posted

Perhaps prepend urls with $page->rootParent->httpUrl? (I haven't used multisite before)
Can you post a screenshot of your page tree? Or the output from your code vs how you want it?

Posted

this is the page tree

image.png.bd36dd7ea62cfd0c44fe7cbfbe6d387c.png

 

The pages Over, Historie, etc should refer to the rootdomain (Home). All other search results should refer to the corresponding domain. All found pages should be in the search results and the links should jump to the corresponding page with correct domain. Otherwise the page doesn't excist.

 This is the basis search code (slightly adapted)

function renderNav(PageArray $items) {

   // $out is where we store the markup we are creating in this function
   $out = '';

   // cycle through all the items
   foreach($items as $item) {

      // render markup for each navigation item as an <li>
      if($item->id == wire('page')->id) {
         // if current item is the same as the page being viewed, add a "current" class to it
         $out .= "<li class='current'>";
      } else {
         // otherwise just a regular list item
         $out .= "<li>";
      }

      // markup for the link
      $out .= "<a href='$item->httpUrl'>$item->title</a> ";

      // if the item has summary text, include that too
      if($item->summary) $out .= "<div class='summary'>$item->summary</div>";

      // close the list item
      $out .= "</li>";
   }

   // if output was generated above, wrap it in a <ul>
   if($out) $out = "<ul class='nav'>$out</ul>\n";

   // return the markup we generated above
   return $out;
}

 

 

 

 

 

 

 

 

 

 

 

Posted
1 hour ago, webhoes said:

I redirect a 404 to the search so that a 404 is never given but a list of relevant pages.

This module will take care of this for you: http://modules.processwire.com/modules/process404-search/

 

53 minutes ago, abdus said:

I don't think preventing 404s is a good idea.

It still returns a proper  404 header, although I am no longer convinced this module/technique is a good idea: https://processwire.com/blog/posts/optimizing-404s-in-processwire/

Posted

I use that module for this. But I need full links with the proper full url in the search results.

I will check your second link and update my knowledge...

Posted
13 minutes ago, webhoes said:

But I need full links with the proper full url in the search results.

What it returns is what your search.php template file returns - if you tweak that to return ->httpUrl you will get what you're looking for. In mine for example:

        foreach($viewableMatches as $m) {
            $content .= '<p><a href="'.$m->httpUrl.'">' . $m->parent->title . ' > ' . $m->title . '</a></p>';
        }

 

Posted

I have this.. but that does not seem to get the correct full url. It still makes links the only have the url that you are on at the moment. The search results all belong to another domain. That is what I want, but the httpUrl should get corresponding domain of that particular page in the search results.

 // markup for the link
      $out .= "<a href='$item->httpUrl'>$item->title</a> ";

 

What does the parent->title do for you. You have more closing tags then opening tags...

Posted

It's not an extra ">" tag - it's a string and makes the link look like a breadcrumb, eg. Furniture > Chairs

As for the other domain issue you are having - sorry I haven't ever used the multisite module, so not the best person to help on that side of things.

 

Posted

@webhoes, I haven't used the Multisite module, but the readme you should have defined separate 404 pages for each domain. So this kind of setup is probably not compatible with Process404Search out-of-the-box.

But based on this section of the readme...

Quote

Just create pages with names like www.campaigndomain.com unter the root page and add these in the config.php via an array in $config->MultisiteDomains.

...you should be able to get the correct links by modifying the search.php adrian refers to above:

foreach($viewableMatches as $m) {
    $url = "{$input->scheme}://{$m->rootParent->name}/{$m->url}";
    $content .= "<p><a href='$url'>$m->title</a></p>";
}

Not tested.

 

Also note that your page tree...

On 04/10/2017 at 12:27 AM, webhoes said:

this is the page tree

image.png.bd36dd7ea62cfd0c44fe7cbfbe6d387c.png

...is what the Multisite readme says not to do:

Quote

TroubleShooting

Wrong page tree structure


- Homepage (main site home)
   - Example Page
   - 404 Page
   - Contact Page
   - www.domain2.com (a second site home)
     - 404 Page
   ...

But this wasn't ever recommended and it can lead to complications.

 

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
  • Recently Browsing   0 members

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