Jump to content

Need to move child page and descendants to root


timothy.m.wilson
 Share

Recommended Posts

Good afternoon. I am trying to figure out how to move a child parent and it's descendants to the root level. 

 

For example, I have:

Home

----Blog

--------Blog Post 1

--------Blog post 2

 

What I would like to have is 

Home

Blog

----Blog Post 1

----Blog Post 2

 

Not as simple as drag and dropped like I had hoped. Hoping there is some kind of module or api call I can make to simplify this. Thanks in advance.

Link to comment
Share on other sites

I could be wrong, but I think Home is the parent of all pages. You can't have another page at that level. What is it you want to accomplish? Maybe there is a means to do so with your current structure.

And welcome to the forum!

  • Like 1
Link to comment
Share on other sites

Hi rick,

Thanks for replying. Based on your feedback, I would be just fine with this structure:

 

Blog

----Blog Post 1

----Blog Post 2

 

Simply removing "Home" would be acceptable. The Blog page is the home page anyways. So, having that at the root level would be good. The end result is to remove the "/blog/" from the url and have the url be "example.com/path-to-blog-post" instead of example.com/blog/path-to-blog-post"

 

Link to comment
Share on other sites

you can rename your homepage to blog, but then you page tree on the backend will show all the posts at the root (sub home) level.

Usually this sort of thing is done using url segments in combination with a page path rewrite hook to make the blog posts live off the root.
Look for the CMS critic case study to see an example of that.

  • Like 3
Link to comment
Share on other sites

Hi timothy,

Since you are only using a blog, you can set the 'Home' Page Title to be whatever you want (eg, Blog), and create your blog posts beneath. So whatever template you currently have defined for your current blog page would be the one to set for the new 'Home' (Blog) Page. You can then promote your blog posts up a level where they reside beneath Blog.

Another option might be url segments.

Link to comment
Share on other sites

Thanks for the feedback guys. I got this one figured out. Just wrote a small script to reset the parent of each blog post and then rendered the blog home page from within the home page template. 

 

$posts = $pages->find("template=blog-post");
    foreach($posts as $post) {
        $post->of(false);
        $post->parent = 1;
        $post->save();
    }

 

and in home.php...

echo $pages->get('/blog/')->render

 

Everything is working as I hoped it would.

Link to comment
Share on other sites

20 hours ago, Macrura said:

Look for the CMS critic case study to see an example of that.

"The main hook of interest is one that makes all posts look like they live off the root "/" level rather than "/posts/" (where they actually live)."

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