Jump to content

Batch activate pages for Multi-lingual support


michelangelo
 Share

Recommended Posts

Hello guys,
I have made a small website that has a few thousand pages with several fields. It all works fine, but when I change my language they don't show up... I found out in the depths of the forum that they need to be activated. Is there any way to do it as a batch process instead of doing in by hand?

Just to clarify, what I need to change is in the Settings of each page, not a field in my template. This 'Active?' button needs to be ticked on every page.

2108474382_Screenshot2020-06-23at14_36_35.thumb.png.606bcd6d35424540a2f30fc32d872289.png

I thought maybe Lister might do the trick, but I can't seem to find a way to affect this Name field.

Thank you!


p.s I am using ImportCSV module to load them up, which works great but I don't think it can apply this setting for me.

Link to comment
Share on other sites

Yes, the "Active" checkbox under the settings tab controls whether the page is viewable in that language. When you create a page through the CMS, it is active in all languages by default. But if you create a page through the API, it is inactive in all non-default languages by default (I've stumbled upon this as well a couple of times, not sure what the resoning behind that is).

You can set the active status through the API, the property is "status{$id}", where {$id} is the ID of the language you want to activate the page in. For example, this code will iterative over a set of pages and activate them in all languages:

$importedPages = wire('pages')->find('template=imported-page'); // adjust the selector as needed
foreach ($importedPages as $p) {
	foreach (wire('languages') as $lang) {
		if ($lang->isDefault()) continue;
		$p->of(false);
		$p->set("status{$lang->id}", 1);
		$p->save();
	}
}

You can put this somewhere in a template file and reload the page once, or execute it through the Console provided by Tracy Debugger.

Of course, if you are importing manually or can use a hook to modify the behaviour of your import module, you can also set this property at the time of importing.

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