tonicastillo

Newbie question: How change homepage

Recommended Posts

Hi

I need to change home page of my one page site. Not only the template, but also content.

Actually page tree is like this:

  • Actual home
    • New home

I would like to move "New home" to root, and delete "Actual home". I thank this would be easy to do, but I don't know how. Two templates allows to have children.

Thanks a lot, (and excuse my english)
I love PW!

Toni Castillo

Share this post


Link to post
Share on other sites

You can kinda "clone" a page into home page like this, but it can't copy image/file fields (as far as I tested).

$source = $pages(1015);
$home = $pages(1);

$source->of(false);
$home->of(false);

// change template (remember to create new template file and allow access to guest users in Template > Access)
// $home->template = $source->template;

foreach($source->template->fieldgroup as $f) {
    if ($home->hasField($f)) $home->$f = $source->$f;
}
$home->save();

 

  • Like 1

Share this post


Link to post
Share on other sites
Quote

of my one page site

Since this is a one page site as you mentioned there cannot be too much content involved and so I wouldn't bother. Create a backup folder alongside your templates folder, download your template files, delete the pages in the tree and setup a new page in the tree with a template file in your backup folder.

You can also make use of Processwires ability to export your templates and fields:

https://processwire.com/talk/topic/11720-export-fieldstemplatesconfiguration-from-one-site-to-another/?do=findComment&comment=108958

 

Share this post


Link to post
Share on other sites

Since this is a one page site there is a lot of content on this page :( . So I think clone it is the best option.

I don't understand why is not a easy way to move a page to root.

Thanks @abdus and @pwired!

 

Share this post


Link to post
Share on other sites

A workaround - though not really pretty - could be:

Assign a new template to the page "Actual home" using this template file (say) redirfirstchild.php:

<?php namespace Processwire;
if($page->numChildren) $session->redirect($page->child()->url);

That would redirect a request of the "Actual home" to the "New home" page.

Downside of this: The URL would become something like "yoursite.com/actualhome/newhome/" (whatever pagenames you use).

To suppress the "actualhome/" part, you perhaps could use URL segments (I don't have any experience with them).

Edit:

And you'd keep the "Actual home" page in the tree (content removed, of course).

Share this post


Link to post
Share on other sites
3 minutes ago, ottogal said:

redirect a request of the "Actual home" to the "New home" page.

That would score worse in terms of SEO, though. Having a homepage that immediately redirects is frowned upon.

3 minutes ago, ottogal said:

To suppress the "actualhome/" part, you perhaps could use URL segments (I don't have any experience with them).

You cannot supress with urlSegments if the page already exists. From @ryan:

Quote

Should there be a child page that has the same name as a URL segment that the parent page's template is looking for, the pages in the tree always have precedence. Meaning, URL segments only apply if the requested URL did not resolve to an actual page. As a result, you should avoid using URL segments where you think the page names and URL segments could collide.

https://processwire.com/docs/tutorials/how-to-use-url-segments/page2

  • Like 1

Share this post


Link to post
Share on other sites

They're quite useful for handling dynamic urls, I'd really suggest practice using them in a project. You're missing out.

Share this post


Link to post
Share on other sites

You might be able to get them working by copying from /site/assets/files/<sourcepageid> to files/1

Share this post


Link to post
Share on other sites

You should also note that the images inside the html CKE fields will still point to the source page. So copying images alone may not be sufficient. 

Share this post


Link to post
Share on other sites

To clone the page seems to be the cleanest approuch after the file/image thing is covered too.

But maybe an Alternative could be to alter the home-template file to get the new page and render this in the home url.

Share this post


Link to post
Share on other sites

 

4 hours ago, abdus said:

You should also note that the images inside the html CKE fields will still point to the source page. So copying images alone may not be sufficient. 

I have no idea why this isn't in the core, but if you are cloning, be sure to use this module: http://modules.processwire.com/modules/process-page-clone-adapt-urls/

  • Like 4

Share this post


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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mcwhitey
      Hi,
      How can I display, on every page of my site, what roles can view that pages template, based on what is checked in settings>templates>template-name>ACCESS TAB?
      I've only gotten as far as displaying the name of the current template: echo $page->template->get('name'); But I'm stuck here. Tried things like $page->template->get('permissions'); but I guess it's a bit more complicated than that.
      Hope someone van point me in the right direction.
      Cheers.
    • By awesomolocity
      Alright. So I'm converting a site I already have to Processwire (really enjoying it so far!). I wanted to convert the previous tables that I had data in to Processwire pages. But I'm wondering what the optimal way to structure pages would be.
       
      So basically, I have three main tables.
      Users (and all accompanying information)
      Items (and all accompanying information)
      Aquariums (each user only has 1 aquarium. Currently, user_id is a FK)
      Fish (type of item. Aquariums may have multiple fish)
      Aqua_settings (Things like lightness, temperature, etc)
       
      So in my current setup, there are a lot of Foreign Keys. I could accomplish essentially the same thing by using the Page Reference field.
      Alternatively, I could make fish and aqua_settings both be children of Aquarium. I could differentiate by doing $aquarium->children('template=aqua_settings'); or something.
       
      So my question is...should I be using the Page Reference field or structuring the pages as children? (Or are both equally fine depending on how I want to go about doing things)
    • By Martin Muzatko
      See gif:

      When I use $sanitizer->pageName()  to sanitize a title as name, I get a different result from what processwire automatically replaces, when editing the name in the CMS.
      I have to manually replace the dashes and even dots!
      I would expect the name to be equal to the last segment of the pagepath.
        
    • By Davidov
      Good Day!
      I am a beginer of processwire project. Thanks developers for your great work. this CMS is very Good!
      I have a question: how get Pageimage object of PageArray from "Page" (PageArray) field type?
      I have too tamplates: affiliates and their teachers. The template of affiliates have a field "teachers_list" wich is "Page" (PageArray) type.
      When I vaffiliate teachers in a cycle, I can not access the teacher photo object and change its size.   I get an error returning: " Fatal error: Call to a member function maxWidth() on null ". When i trying get URL attribute : $teacherItem->teacher_photo->url, i receive message: " Trying to get property of non-object ".   But this code works: $teacherItem->teacher_photo["url"].   The print_r function outputs the following information: "ProcessWire \ Pageimage Object ([changes] => Array ([0] => formatted) [hooks] => Array ([Pageimage :: pim2Load] => PageImageManipulator02-> getPageImageManipulator02 () in PageImageManipulator02.module ) [Data] => Array ([basename] => p16.jpg [description] => .... - ..... [tags] => [formatted] => 1 [modified] => 1487079115 [created ] => 1487079115))".   my PHP code: foreach ($page->teacher_list as $teacherItem): $out .= " <tr> <td class=\"alignTop\"> /* !!! my truble */ <img src=\"{$teacherItem->teacher_photo->maxWidth(250)->url}\" /> /* !!! my truble */ </td> <td class=\"alignTop\"> <div class=\"teach_style12\"> <strong>$teacherItem->fio</strong><br/> $teacherItem->degree<br/> $teacherItem->headline_detail </div> <div class=\"teach_style9\"> $teacherItem->body </div> </td> </tr>"; endforeach; Please, help me. Where is my error?
       
    • By Mirza
      Hi All,
      I have created a script which will create the pages and it should be unpublished.
      I have added the status as unpublished by default while first time saving the page as below.
      $hotelPage->hotel_website = $hotel['hotelWebsite']; // By default page created will be unpublished state $hotelPage->addStatus(Page::statusUnpublished); $hotelPage->save(); $hotelPage->setOutputFormatting(false); // Add hotel images only after setting output formatting to false $hotelPage->images->add($hotel['hotelImage']); $hotelPage->save(); On the same time, saving the hotel image as well and triggering the save method.
      But when I see the created page in the tree, Its shows unpublished but publish_date is not empty(date will be present as created, modified and published are all same)
      Now I don't understand why the date is getting filled into the publish field for a page?
      Please let me know if am doing something wrong.