Add to top
Permalink 2 users found helpful
Hi Guys
I get asked the same question by every single client with a c5 website.
"So how do I add a block to the top of an area?"
My reply is always a painful...
"Well you have to add the the bottom, click reorder, drag it all the way up to the top, click save order"
And they always say back. "Eugh, why not just had an add to top, or at least a send to top option"
I couldn't agree with them more, this seems like such a basic usability problem that should be sorted as a matter of urgency.
Either an 'Add here' / 'Add to top' on the area contextual menu, or a 'Send to top' in the contextual menu options of that block.
Thoughts?
Ben
I get asked the same question by every single client with a c5 website.
"So how do I add a block to the top of an area?"
My reply is always a painful...
"Well you have to add the the bottom, click reorder, drag it all the way up to the top, click save order"
And they always say back. "Eugh, why not just had an add to top, or at least a send to top option"
I couldn't agree with them more, this seems like such a basic usability problem that should be sorted as a matter of urgency.
Either an 'Add here' / 'Add to top' on the area contextual menu, or a 'Send to top' in the contextual menu options of that block.
Thoughts?
Ben
Hey there!
I had the same problem and fixed it by changing some PHP code.
My solution will display the <Add to...> box before the existing blocks as well show as the blocks in reversed order:
<Add to...>
<existing blocks>
Since I only wanted to change this for the Main Area (and leave Sidebar and Header as it is), I created a new function that I only use for this one area.
1. Copy 2 files from the core
cp concrete/models/area.php models/
cp concrete/elements/block_area_footer.php elements/block_area_footer_reverse.php
(so that our code wont be overwritten when concrete5 is updated)
2. file: models/area.php
find the display() function and copy it to display_reverse() function. All changes will be contained in this new function.
2.1 look for:
and put a new line BEFORE it:
this will revert the order in which the posts are displayed
2.2 look for:
(it's after the foreach() block)
move this code block infront of your new line and make a small change to it.
Result:
this will bring the <Add to...> box to the top
All is good, except that after you create a new block, it will look like this:
<new block>
<Add to...>
<existing blocks>
But we want it to look like that:
<Add to...>
<new block>
<existing blocks>
that is why we need to change the second file:
3. file: 'elements/block_area_footer_reverse.php'
This file holds the <Add to...> box, but also the newly created block (in case a new block was just created).
3.1
move this code block from the top to the bottom of the file.
That's it. Now you only have to use the new function display_reverse() instead of display() in the choosen area.
If you are looking to change the block order in your Main Area, look for
in the theme that you are currently using (inside concrete/themes/ or themes/ ).
Now change
to
Make sure cache is empty, reload and there you go :).
Hope that's helpful!
Meg
I had the same problem and fixed it by changing some PHP code.
My solution will display the <Add to...> box before the existing blocks as well show as the blocks in reversed order:
<Add to...>
<existing blocks>
Since I only wanted to change this for the Main Area (and leave Sidebar and Header as it is), I created a new function that I only use for this one area.
1. Copy 2 files from the core
cp concrete/models/area.php models/
cp concrete/elements/block_area_footer.php elements/block_area_footer_reverse.php
(so that our code wont be overwritten when concrete5 is updated)
2. file: models/area.php
find the display() function and copy it to display_reverse() function. All changes will be contained in this new function.
2.1 look for:
foreach ($blocksToDisplay as $b) {
and put a new line BEFORE it:
$blocksToDisplay = array_reverse($blocksToDisplay);
this will revert the order in which the posts are displayed
2.2 look for:
if (($this->showControls) && ($c->isEditMode() && ($ap->canAddBlocks() || $u->isSuperUser()))) { $bv->renderElement('block_area_footer', array('a' => $ourArea)); }
(it's after the foreach() block)
move this code block infront of your new line and make a small change to it.
Result:
if (($this->showControls) && ($c->isEditMode() && ($ap->canAddBlocks() || $u->isSuperUser()))) { $bv->renderElement('block_area_footer_reverse', array('a' => $ourArea)); $blocksToDisplay = array_reverse($blocksToDisplay); foreach ($blocksToDisplay as $b) {
this will bring the <Add to...> box to the top
All is good, except that after you create a new block, it will look like this:
<new block>
<Add to...>
<existing blocks>
But we want it to look like that:
<Add to...>
<new block>
<existing blocks>
that is why we need to change the second file:
3. file: 'elements/block_area_footer_reverse.php'
This file holds the <Add to...> box, but also the newly created block (in case a new block was just created).
3.1
move this code block from the top to the bottom of the file.
That's it. Now you only have to use the new function display_reverse() instead of display() in the choosen area.
If you are looking to change the block order in your Main Area, look for
$a = new Area('Main');
in the theme that you are currently using (inside concrete/themes/ or themes/ ).
Now change
$a->display($c);
to
$a->display_reverse($c);
Make sure cache is empty, reload and there you go :).
Hope that's helpful!
Meg
Is this function still useable in the new concrete 5.5.1?
Hello !
Thank you very much for sharing this tweak.
I tried it and it almost worked.
The only weird thing is that my blocks don't appear when I leave edit mode, yet, they are all in the right order when in edit mode.
Other weird thing is when I was following your instructions for the area.php method, after I'd finished, I received a syntax error in php I assumed it was a misclosed "}" so I added one, otherwise my website would crash, and I wouldn't be able to load any page.
Can you help me ?
//////////// EDIT//////////
Nevermind, I found my mistake !
Thank you very much for sharing this tweak.
I tried it and it almost worked.
The only weird thing is that my blocks don't appear when I leave edit mode, yet, they are all in the right order when in edit mode.
Other weird thing is when I was following your instructions for the area.php method, after I'd finished, I received a syntax error in php I assumed it was a misclosed "}" so I added one, otherwise my website would crash, and I wouldn't be able to load any page.
Can you help me ?
//////////// EDIT//////////
Nevermind, I found my mistake !
Can you please explain what your mistake was and how you fixed it? It might be helpful to someone else in the future.
I basically went past a step and therefore ther was a missing “ } “ in my php, I took it all over step by step and the magic happened.
On 2.2 above, what happened to the ending '}' when you move that code block to the front of the new line?
Does the '}' stay where it originally was or do you move the '}' to the top with the whole code block?
Reason I am asking is because I am getting a fatal error saying that this function "display_reverse" does not exist.
Please help.
Does the '}' stay where it originally was or do you move the '}' to the top with the whole code block?
Reason I am asking is because I am getting a fatal error saying that this function "display_reverse" does not exist.
Please help.
I don't know much about this thing, but looking at the original instructions I see step 2 is this:
----
2. file: models/area.php
find the display() function and copy it to display_reverse() function. All changes will be contained in this new function.
----
...if you're getting an error saying there's no "display_reverse()" function, that probably means you left out this step.
----
2. file: models/area.php
find the display() function and copy it to display_reverse() function. All changes will be contained in this new function.
----
...if you're getting an error saying there's no "display_reverse()" function, that probably means you left out this step.
Thanks for the quick reply Jordan. I see what you mean.
Just looked over it - nope, I did not skip this step. I created a new display_reverse function as it says above.
I went over this whole thing probably 3-4 times and I'm still trying to figure out where that last '}' goes.
Just looked over it - nope, I did not skip this step. I created a new display_reverse function as it says above.
I went over this whole thing probably 3-4 times and I'm still trying to figure out where that last '}' goes.
I can't figure this out either, fatal errors for africa. probably because I know nothing about PHP. Wish someone would just write a function for me that will work if possible??
Hi meg,
thanks for this, I was wondering though would it be possible to create a file i can upload to c5 which will handle this function? As in somewhere we can download a solution and start using it straight away. Would be really helpful. Especially for newbs like myself.
thanks for this, I was wondering though would it be possible to create a file i can upload to c5 which will handle this function? As in somewhere we can download a solution and start using it straight away. Would be really helpful. Especially for newbs like myself.
Core classes were shuffled around in 5.6. The file is now here:
/concrete/core/models/area.php
/concrete/core/models/area.php
I tried this but I got always this error:
Class 'Area' not found in /xxxxxx/concrete/core/models/block.php on line 64
The problem must be in the /models/area.php
because when I rename the file CC5 works again.
(files attached)
Can anyone help me with this problem?
I use the current version 5.6.0.2
Class 'Area' not found in /xxxxxx/concrete/core/models/block.php on line 64
The problem must be in the /models/area.php
because when I rename the file CC5 works again.
(files attached)
Can anyone help me with this problem?
I use the current version 5.6.0.2
Core classes were shuffled around in 5.6.
The top of your custom area.php file should be this:
(not "class Concrete5_Model_Area extends Object {" like you currently have).
The top of your custom area.php file should be this:
class Area extends Concrete5_Model_Area {
(not "class Concrete5_Model_Area extends Object {" like you currently have).
Meg83's solution is brilliant, and I will definitely be using that in future when needed.
But I want to address the OP's statement about always wanting to add blocks to the top of a page -- I used to think this as well but I realized that in most situations when this was being asked for, it was better solved by making each item in the list its own page beneath a top-level page, and then in the top-level page you have a page list block that displays in reverse-chronological order. The free Page List Teasers addon is very useful for this kind of setup because it lets you show actual content from the sub-pages, as opposed to just the description:
http://www.concrete5.org/marketplace/addons/page-list-teasers...
I also created the free "Force Single Sublevel" addon for these kinds of situations -- it makes it much easier for users to add pages and have them wind up in the proper place:
http://www.concrete5.org/marketplace/addons/force-single-sublevel/...
-Jordan
But I want to address the OP's statement about always wanting to add blocks to the top of a page -- I used to think this as well but I realized that in most situations when this was being asked for, it was better solved by making each item in the list its own page beneath a top-level page, and then in the top-level page you have a page list block that displays in reverse-chronological order. The free Page List Teasers addon is very useful for this kind of setup because it lets you show actual content from the sub-pages, as opposed to just the description:
http://www.concrete5.org/marketplace/addons/page-list-teasers...
I also created the free "Force Single Sublevel" addon for these kinds of situations -- it makes it much easier for users to add pages and have them wind up in the proper place:
http://www.concrete5.org/marketplace/addons/force-single-sublevel/...
-Jordan
Jordan and meg83 your my heros!
Isn't this a basic requirement? I've got a site that will be news intensive over a two-week period, and naturally, I would like to add the latest news to the top of main.
I find that I prefer to use a Page List to Page rather than an Area to Block structure for 'News' sections. That way you also ensure that your page will have a full URL for SEO purposes and such. And of course with a Page List, you can set those to display the most recent pages first and such.
I agree 100% with @aghouseh -- it requires changing the way you think about building websites a little, but I feel this is truly the "Concrete5 Way", and the more you can organize your site to fit within this model, the easier it will be to develop with C5.
Hi Guys,
can't move blocks on pages with display_reverte (no drag and drop).
The order is in edit mode revers (oldest on top).
Any Idea (used finegermandesign's files)? Can it be thad area.php has changed since last version?
Regards
Torsten
can't move blocks on pages with display_reverte (no drag and drop).
The order is in edit mode revers (oldest on top).
Any Idea (used finegermandesign's files)? Can it be thad area.php has changed since last version?
Regards
Torsten
Anyone?
There was a pull request to do 'add to top', see
https://github.com/concrete5/concrete5/pull/777... and
http://www.concrete5.org/developers/beta/beta_discussion/block-edit...
(you will need access to the beta forum)
The pull was closed with the promise that this functionality will be in v5.7 of c5, but not in the same way.
In the mean time, I have been using mlocati's code from the pull and it is working great!
https://github.com/concrete5/concrete5/pull/777... and
http://www.concrete5.org/developers/beta/beta_discussion/block-edit...
(you will need access to the beta forum)
The pull was closed with the promise that this functionality will be in v5.7 of c5, but not in the same way.
In the mean time, I have been using mlocati's code from the pull and it is working great!
Hi John,
thanks for the tip - but can't get it running (white screen).
use the last master from github.
What means
"Please note that the ccm.app.js file should be regenerated since I modified the ui.js file"
regenerated?
Maybe you could send me the files I need (I tried it with copy & paste from GitHub)?
Regards
Torsten
thanks for the tip - but can't get it running (white screen).
use the last master from github.
What means
"Please note that the ccm.app.js file should be regenerated since I modified the ui.js file"
regenerated?
Maybe you could send me the files I need (I tried it with copy & paste from GitHub)?
Regards
Torsten
2¢