display all posts under domain/blog/post

Post Reply
User avatar
Jay
Ssr. Bludit
Posts: 29
Joined: Mon Feb 11, 2019 8:41 pm

Mon Feb 11, 2019 10:01 pm

Hello
I'm struggling with a problem how to make bludit display blog posts under /blog/ parent. Every approach I tried ended up with more errors to bare with.

I've read all posts about similar question on this forum, and github issues, but all provided solutions aren't working in the way I'd be satisfied.
I'd like to:
1. show last 3 blog posts on homepage
2. show all blog posts with pagination under static page, assuming its slug (uri) is set as 'blog'. Blog posts should be accessible with domain.ext/blog/post1, /blog/post2 and so on
3. leave all other static pages with their default behaviour, without any redirects, filters, just as default top level pages

I base on devtheme, latest B 3.7.1 (github-master), and apache webserver (shared hosting provider)

1. I cannot set /blog/ in settings > advanced > filters, because all pages both static and posts are redirected to domain/blog/slug
This ends up with "404 page not found"
Adding redirects to .htaccess - which was one of users solution - does not change anything, it's a problem with filtering.
I've tried to set a different page as homepage. Things got even worse.

2. I thougt I'll come up with additional template file for a blogroll (list of all blog posts).

I created a new static page with 'blog' in friendly url field, and set a fixed template name 'blogroll' in page's advanced settings

Then I've created an additional template/php/blogroll.php file for this static page, which lists all published posts - it's literally a copy of home.php, just to make things work in a raw way.

In themes/theme/index.php I conditionally load the blogroll.php for page with blogroll in its options, with 'blog' as its uri, and for a static type of page - just to load it only for this one particularly page, and list all posts.
Until this part everything was working.

/blog page loads the blogroll.php template file, but errors gallery starts to appear. I cannot use devtheme's builtin' foreach loop to show , as It only gets the "blog" static page's content. Thus I reworked the loop using method desribed in docs to list all posts:
https://docs.bludit.com/en/dev-snippets/content-pages

Still two problems.
1. setting lower amount of posts to show per page in advanced option, to force pagination doesn't work as supposed. Pagination shows up, but all the posts are being show on all subpages with older entries. I'm unable to come up with a fix for this.
2. this is a minor thing, but I thought about providing a parent page for all posts. Unfortunately static page cannot be set as a parent in page's advanced settings.

I feel that all 3 things I'd want to achieve may somehow be done in easier way.
But my knowledge of php and skills in programming are apparently insufficient to achieve - one could possibly think - such easy thing available out of box in most popular CMSes.
User avatar
Edi
Site Admin
Posts: 1411
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Tue Feb 12, 2019 12:01 am

Jay wrote:
Mon Feb 11, 2019 10:01 pm
/blog page loads the blogroll.php template file, but errors gallery starts to appear. I cannot use devtheme's builtin' foreach loop to show , as It only gets the "blog" static page's content.
What do you mean with "errors gallery starts to appear"?

How have you set the conditions for the template blogroll.php in the file index.php?
But my knowledge of php and skills in programming are apparently insufficient to achieve - one could possibly think - such easy thing available out of box in most popular CMSes.
Fine if you know one. I don't know any. ;-)
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
diego
Site Admin
Posts: 679
Joined: Sat May 16, 2015 2:53 pm
Contact:

Tue Feb 12, 2019 10:22 am

I feel that all 3 things I'd want to achieve may somehow be done in easier way.
But my knowledge of php and skills in programming are apparently insufficient to achieve - one could possibly think - such easy thing available out of box in most popular CMSes.
If you feel is missing some feature you can request it in Github Issues https://github.com/bludit/bludit/issues
User avatar
Jay
Ssr. Bludit
Posts: 29
Joined: Mon Feb 11, 2019 8:41 pm

Tue Feb 12, 2019 10:37 am

zarzud.ga - blog about nothing and all
Edi wrote:
Tue Feb 12, 2019 12:01 am
Jay wrote:
Mon Feb 11, 2019 10:01 pm
/blog page loads the blogroll.php template file, but errors gallery starts to appear. I cannot use devtheme's builtin' foreach loop to show , as It only gets the "blog" static page's content.
What do you mean with "errors gallery starts to appear"?

How have you set the conditions for the template blogroll.php in the file index.php?
Hi Edi, thanks for replying.
The last condition I left in index. php

Code: Select all

 
if ($WHERE_AM_I == 'page' && $page->slug() != 'blog') {
include(THEME_DIR_PHP.'page.php');
}	
elseif ($page->slug() == 'blog' && $page->isStatic()) 
{
include(THEME_DIR_PHP.'blogroll.php');
}
The theme file is loaded as supposed.
But leaving the default loops from devtheme's home.php isn't working as supposed. The loop lists only the static blog page, without any other posts.
I tried to load whole database and iterate through it.
For example ending up with loading only posts using $posts = $pages->db; leave to access errors, so I couldn't iterate using devtheme's methods like $page->permalink(), $page->title(); and so on.
Thus I used the loop from docs as the buildPage($key) function was crucial.

And guess what:
99 little bugs in the code,
take one down,patch it around.
127 little bugs in the code...
:lol:
Posts showed up, but pagination isn't working. All posts are being shown on every paginated page. At this point I'd need to disable somehow pagination, and leave a wall of posts in this state. Every solution leads into more problems.

Other thing is that I'd still need to set a parent page (the one with 'blog' slug) for all posts to make their uri's to be domain.ext/blog/post1
But bludint doesn't allow to set a parent, if the parent is a static page.

I guess the idea cannot be implemented with current bludit version in an quite easy way. It consumes more and more time trying to find another solution, but it ends up generating more problems than it solves.
Edi wrote:
Tue Feb 12, 2019 12:01 am
But my knowledge of php and skills in programming are apparently insufficient to achieve - one could possibly think - such easy thing available out of box in most popular CMSes.
Fine if you know one. I don't know any. ;-)
At this moment I have already working theme and I'm not willing to try out another cms just to achieve the posts showing up under another page.
Even if, I doubt there's any other flat file management system I didn't touch in my life. Grav for example has everything needed, but It's to heavy for my taste. Not to mention using joomla - a heavy cannon for all purposes.
The one I'm most familiar with - getsimple cms - isn't suitable for blog sites.
Last edited by Jay on Sun Feb 24, 2019 11:48 pm, edited 1 time in total.
User avatar
Edi
Site Admin
Posts: 1411
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Thu Feb 14, 2019 1:08 pm

I see the problem. I don't know at the moment if this configuration is possible without modifying the core.
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
Post Reply