[SOLVED] Onepager Theme

nion
Posts: 16
Joined: Thu Nov 02, 2017 10:32 am

[SOLVED] Onepager Theme

Post by nion »

Hello
I'm trying to create an onepager theme.

I like to display all db entries in the first page. I tried that with the following code (from the Blog Project):

Code: Select all

	
	<?php
	$class = "";
	if  ( wCMS::$loggedIn ) {
   	$class = "editText editable";
	}
	?>
	
	<?php foreach ( wCMS::db()->pages as $pageName => $page ): ?> <!-- loop though all pages -->
	<div class="container" id="<?=$page->title; ?>">
		<div class="row">
			<div class="col-lg-12 text-center padding40">
				<div class="<?php print $class; ?>"><?=$page->content; ?></div>
			</div>
		</div>
	</div>
	<?php endforeach; ?>
It shows every content, but without the addition_content. The content is unfortunately not editable.
Does somebody has any idea?

Thx
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Onepager Theme

Post by wiz »

Here's a short snippet that will show the additional contents and also make them editable.
Replace the bottom code with the one you pasted earlier and please make a backup before doing any changes.

Code: Select all

	// NEW CODE IN POST BELOW 
Note: This is just a quick/dirty solution, you are welcome to experiment with this!
Note 2: The above script will show a maximum of 10 additional contents per page, if you want to increase the limit, change one number in:

Code: Select all

for ($i=1; $i!=10; $i++)
to

Code: Select all

for ($i=1; $i!=50; $i++)
This changes the limit to 50 additional contents.
nion
Posts: 16
Joined: Thu Nov 02, 2017 10:32 am

Re: Onepager Theme

Post by nion »

Hi wiz

Thank you so much for the support!
Your code snippet work fine, the content will display correctly with the additional content.
In the admin it's editable but it don't save anything to db
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Onepager Theme

Post by wiz »

Forgot to add

Code: Select all

data-target="pages"
Below is the updated code which saves changes to database correctly.

Code: Select all

	<?php
	$class = "";
	if  ( wCMS::$loggedIn ) {
        $class = "editText editable";
	}
	?>

	<?php foreach ( wCMS::db()->pages as $pageName => $page ): ?> <!-- loop though all pages -->
    	<div class="container" id="<?=$page->title; ?>">
    		<div class="row">
    			<div class="col-lg-12 text-center padding40">
    				<div class="<?php print $class; ?>"><?=$page->content; ?></div>
                	  <?php
                		for ($i=1; $i!=10; $i++) {
                		    $numberOfContent = "addition_content_".$i;
                		    $fetch = $page->$numberOfContent;
                	        $addition_content = $fetch;
            			    if (empty($addition_content)) {
            			        // do something if the additional content doesn't exist, maybe don't
                			} else { ?>
                    			<div data-target="pages" class="<?php print $class; ?>" id="<?php print $numberOfContent; ?>"><?=$fetch;?></div>
                		    <?php
                			}
                		}
                	?>
    			</div>
    		</div>
    	</div>
	<?php endforeach; ?>
nion
Posts: 16
Joined: Thu Nov 02, 2017 10:32 am

Re: Onepager Theme

Post by nion »

Hi
Editing works only for the first entry.
I've another idea, is it possible if you logged in to get a another theme
Something like that:

Code: Select all

		<?php
	if  ( wCMS::$loggedIn ) {
        $theme = "admin";
	}
	?>
greets

edit: I find a Solution by myself

Code: Select all

<?php if( wCMS::$loggedIn ) : ?>
 content for admin
<?php else : ?>
content for visiter
<?php endif; ?>
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Onepager Theme

Post by wiz »

Awesome and congratulations on finding a solution. :thumbsUP:.
Editing works only for the first entry.
I have tested multiple entries and it saves the second one also correctly. Are you still having this issue?
nion
Posts: 16
Joined: Thu Nov 02, 2017 10:32 am

Re: Onepager Theme

Post by nion »

Your right it works for the current page entries (content and additonal_content).
But the second page entries doesn't save anithing.
If you change the site over the menu (wondercmd.com/page2) it save also in the first db entrie (page1)
I hope you understand my English

greets
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Onepager Theme

Post by wiz »

Understood, I will tackle this issue in a couple of hours and report back. ;)
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Onepager Theme

Post by wiz »

I had a chance to test this out and after further inspection I don't think editing all additional contents will be possible on one page.

Please imagine the example below for easier understanding:

Page 1
- content (not additional)
- additional_content_1
- additional_content_2

Page 2
- content (not additional)
- additional_content_1
- additional_content_2

When we are listing everything on Page 1, it shows as:
Page 1
- content (not additional)
- additional_content_1
- additional_content_2
- additional_content_1 (from Page 2)
- additional_content_2 (from Page 2)

WonderCMS works in a way that reads these "additional_content" from the database and displays them in their own <div>'s.
Example of how this is displayed in HTML:

Code: Select all

<div data-target="pages" id="addition_content_1" class="editText editable">Additional content from Page 1</div>
<div data-target="pages" id="addition_content_2" class="editText editable">Additional content from Page 1</div>
<div data-target="pages" id="addition_content_1" class="editText editable">Additional content from Page 2</div>
<div data-target="pages" id="addition_content_2" class="editText editable">Additional content from Page 2</div>
The problem comes when it's time so save changes, as you are describing - this happens:
Each time you make a change to the same "id" listed below (additional_content_1 and _2), your content doesn't get saved OR worse, it gets overwritten because it has the same id. These id's are a way of WonderCMS to recognize what field is being edited and saved.

So in short: listing all additional contents is possible on one page, but not editing because they would overwrite one another. To edit the additional fields, you will have to visit the page where the additional content originates from (so these additional contents can be edited if you visit their /page (their origin)).

The short script I pasted a couple of days earlier always shows all additional content fields on ALL pages. To make it only show on one page (for less confusion when visiting other pages), something like this would work.

Code: Select all

<?php
	$class = "";
	if  ( wCMS::$loggedIn ) {
        $class = "editText editable";
	}
?>

<?php if (wCMS::$currentPage == 'home'): ?>
	<?php foreach ( wCMS::db()->pages as $pageName => $page ): ?> <!-- loop though all pages -->
		<div class="container" id="<?=$page->title; ?>">
			<div class="row">
				<div class="col-lg-12 text-center padding40">
					<div class="<?php print $class; ?>"><?=$page->content; ?></div>
						<?php
							for ($i=1; $i!=10; $i++) {
								$numberOfContent = "addition_content_".$i;
								$fetch = $page->$numberOfContent;
								$addition_content = $fetch;
								if (empty($addition_content)) {
									// do something if the additional content doesn't exist, maybe don't
								} else { ?>
									<div data-target="pages" class="<?php print $class; ?>" id="<?php print $numberOfContent; ?>"><?=$fetch;?></div>
								<?php
								}
							}
						?>
					</div>
			</div>
		</div>
	<?php endforeach; ?>
<?php endif ?>
Edit the above home in

Code: Select all

<?php if (wCMS::$currentPage == 'home'): ?>
to show this only on a specific page.

This will list all additional fields on the home page. If you visit yourdomain.com/someOtherPage that has additional content fields, edit it there and it will display correctly on the home page.

Hope this helps, let me know if you need any assistance.
nion
Posts: 16
Joined: Thu Nov 02, 2017 10:32 am

Re: Onepager Theme

Post by nion »

Thank you for your short script.
My solution for a one pager theme:

Code: Select all

<?php if( wCMS::$loggedIn ) : ?>
 content for admin
<?php else : ?>
content for visiter
<?php endif; ?>
So here is the result: https://github.com/niondevelop/oner
The code is very messy, but it works :roll:.

greets
Last edited by nion on Thu Nov 16, 2017 5:17 pm, edited 1 time in total.
Post Reply