Get Parent pages / child page content in Bludit 2.0

Post Reply
User avatar
VanHalen
Jr. Bludit
Posts: 9
Joined: Wed Jun 29, 2016 2:48 pm
Location: The Netherlands

I'm currently updating (locally) a website for a client which runs on Bludit 1.4.

The update went ok, no real issues in the backend. on the frontend all custom functions stopt working as expected. In the past i used a function like below, to get child page content and output custom menu's, page content, etc:

Almost everything depended on, $pagesParents[NO_PARENT_CHAR];

Code: Select all

function getSubPage($name, $title=true) {
	
	global $Page, $pagesParents;

	$parents = $pagesParents[NO_PARENT_CHAR];
	
	foreach($parents as $parent):
	
		if( $parent->published()):
	
			if(isset($pagesParents[$parent->key()])):
	
				$children = $pagesParents[$parent->key()];
	
				foreach($children as $child):
					if ($child->slug()!=$name):
					elseif($child->slug()==$name && $title):
					   echo $child->title();
					   echo $child->content();
					endif;
				endforeach;
		
			endif;
		endif;
		
	endforeach;
}
What is the right way to get child content, page titles, etc. in Bludit 2.0? I'm currently looking in to getParents(), getStaticDB() But the page title is not present in the Array output of these functions.

Is there another way to do this? Or does anyone know how to update the code above?
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

I think child pages are not available in Bludit 2.0 at all, see my post viewtopic.php?f=6&t=1006. Only posts (now called published) can be cascaded, not pages (now called static). That does not make sense to me and is not the usual behaviour of content management systems.
On Error GoTo Bed
User avatar
VanHalen
Jr. Bludit
Posts: 9
Joined: Wed Jun 29, 2016 2:48 pm
Location: The Netherlands

Mmmm, thats not good news if true.

There is a way to do it, but i don't want to load the complete content for all pages, just to find the page title.

That's bloated in my opinion, since i only need the page/content (what is it called now?) ID or title and then decide if want to load the content or use it for a custom menu layout.

If this (still) exists i have no problem dividing content and displaying it where i want it. I would use static as content snippets on a content page to display extra info and use content with a special category for blog posts, etc. but overall the backend could use a better way for dividing content, 1-100 pages would eventually not work.

Many things changed since my last visit, 1.4 but i do not need to update if it's not possible anymore, but will move new projects which could run on Bludit to another cms.
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

You could upgrade to version 1.6.2 (https://github.com/bludit/bludit/releases/tag/1.6.2), which is still available and should work without any issues.

In version 2.0, everything is called content, there is no more difference between pages and posts, technically. Content can be saved as static or published, which is similar to pages and posts in the 1.x versions, if you like. The programming is easier, as Diego and Edi say.
On Error GoTo Bed
User avatar
VanHalen
Jr. Bludit
Posts: 9
Joined: Wed Jun 29, 2016 2:48 pm
Location: The Netherlands

Thanks for the info.

I need to inspect this 'new way' more before condoning it as something i cannot use.

And maybe i find a way around it for the 'old' 1.4 website. The Bludit API could do it, so that could be the solution for updating to 2.0 eventually.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Torsten_Kelsch wrote: Thu Oct 19, 2017 1:05 pm I think child pages are not available in Bludit 2.0 at all, see my post viewtopic.php?f=6&t=1006. Only posts (now called published) can be cascaded, not pages (now called static). That does not make sense to me and is not the usual behaviour of content management systems.
You are thinking to complicated!

Bludit 2 uses content, that can be used for blogs (ordered by date) and websites (ordered by position) and blogs with pages (content ordered by date and static content). Content ordered by date can have parents/child. For static content it is at the moment not yet possible. But I think this could be done easily.

There is nothing like a usual behaviour of a CMS. Every CMS has is own structure and terminology. Also it makes no sense to mix up systems for blogging and content management. With Bludit 2 you can decide to have a blog or a CMS. In addition to this you can have a blog with static content or static content with a blog.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

VanHalen wrote: Wed Oct 18, 2017 2:29 pm In the past i used a function like below, to get child page content and output custom menu's, page content, etc:
Where do you use the code? In a plugin?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

There are some clarifications: viewtopic.php?f=13&t=1016. In short: Published content can be sorted by date or by position and can have sub content. Static pages can’t have sub pages at the moment, but as Edi told me, this is only a bug and will be fixed. So, let’s simply be patient, everything will turn out fine.
On Error GoTo Bed
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

Hi VanHalen,
I use similar case for the documentation, https://docs-v2.bludit.com/en/

Take a look at the sidebar
https://github.com/bludit-themes/docs/b ... idebar.php

Here is a list of `"content" global variables you can use, there are some comments there and who they are defined.
https://github.com/bludit/bludit/blob/m ... .pages.php

Here is a little code you can try

Code: Select all

<?php

foreach ($pagesByParent[PARENT] as $Parent) {

	// $Parent is a Page Object
	echo 'Parent title' . $Parent->title();

	// Check if the parent has sub-pages/children
	if (!empty($pagesByParent[$Parent->key()])) {

		// Foreach sub-page/children
		foreach ($pagesByParent[$Parent->key()] as $Child) {

			// $Child is a Page Object
			echo 'Child title' . $Child->title();
		}
	}
}
Post Reply