Digital experiences for all disciplines
New Landing › How can we help? › Cardinal › Sort Saved elements in page builder by name ASC/DESC
New Landing › How can we help? › Cardinal › Sort Saved elements in page builder by name ASC/DESC
- This topic has 8 replies, 3 voices, and was last updated 10 years by Rui Guerreiro – SUPPORT.
-
Posted in: Cardinal
-
November 7, 2014 at 12:32 pm #126467
Hello,
I am trying to sort the saved elements in the page builder. I’m quite sure this must be done in the file “layouts” (cardinal/swift-framework/page-builder/inc). Most probably in line 165:
class SPBElementsMenu implements SPBTemplateInterface {
protected $params = Array();public function setup( $params ) {
$this->params = (array) $params;return $this;
}public function output( $post = null ) {
if ( empty( $this->params ) ) {
return ”;
}
$output = ‘<li class=”nav-header”>’ . __( ‘Load Element’, ‘swift-framework-admin’ ) . ‘‘;
$is_empty = true;
foreach ( $this->params as $id => $element ) {
if ( is_array( $element ) ) {
$element_button = new SPBSavedElementsMenuButton();
$output .= $element_button->setup( $element )->setID( $id )->output();
$is_empty = false;
}
}
if ( $is_empty ) {
$output .= ‘<li class=”spb_no_elements”><span>’ . __( ‘You have not saved any elements yet.’, ‘swift-framework-admin’ ) . ‘</span>‘;
}return $output;
}
}But somehow I can’t manage to sort the array as the usual wordpress manner:
( array ( ‘orderby’ => ‘title’, ‘order’ => ‘DESC’ ) );Also, if possible, I would like to know how to group the items by some Html tags as titles, hr, etc.
Thanks a lot,
RicardNovember 7, 2014 at 7:11 pm #126567Hi,
You should look in the class SPBElements_r and adapt the function getElementsList() to modify the array of elements and return it with your desired order.
The loop is build in cardinal\swift-framework\page-builder\inc\layouts.php around line 332
-Rui
November 8, 2014 at 12:10 pm #126637Hello,
Thanks for your hint. I’ve been trying many things without success. Please can you show me the way to sort it by noame/title? So far I’ve been trying things like these, trying with “name” or “title” for the “orderby”:
Your help will be much appreciated.
Cheers,
R.class SPBElements_r extends SFPageBuilderAbstract { protected $elements = Array( 'orderby' => 'name', 'order' => 'DESC' ); public function getMenu() { $elements_menu = new SPBElementsMenu(); return $elements_menu->setup( $this->getElementsList() )->output(); } protected function getElements() { if ( $this->elements == null ) { $this->elements = (array) get_option( 'spb_elements' ); } return $this->elements; } public function getElementsList() { $this->elements = (array) $elements; return $this; } } ////////////// public function getTemplatesList() { $this->elements = (array( 'orderby' => 'name', 'order' => 'DESC' )); return $this->getTemplates(); } ////////////// public function getElementsList() { $resultat = array('orderby' => 'name', 'order' => 'DESC'); $this->elements = (array) $resultat; return $this->getElements(); } ////////////// public function getElementsList() { $this->getElements(array( 'orderby' => 'title', 'order' => 'DESC' )); return $this->elements; } ////////////// public function getElementsList() { asort($elements); foreach ($elements as $key => $val) { echo "$val"; }
November 10, 2014 at 9:14 am #126869Hi
I’ve forwarded this to Rui, he will assist you shortly ๐
– Kyle
November 11, 2014 at 12:02 pm #127286Thanks,
I’ll be looking forward.
Cheers.
November 11, 2014 at 3:26 pm #127376Hi,
The idea was to show you the way. This is an example of an array with 2 itens.
https://www.dropbox.com/s/6dcrduu6sf2dahq/elemens_array.png?dl=0This is a customization that could be complicated and take sometime so that’s outside the scope of our support because we just don’t have enough time to do it.
This is the specific place where the array should be manipulated:
protected function getElements() { if ( $this->elements == null ) { $this->elements = (array) get_option( 'spb_elements' ); } //here manipulate $this->elements return $this->elements; }
-Rui
November 25, 2014 at 10:17 am #130830Hi Rui,
Finally we managed to do it with this:
protected function getElements() { if ( $this->elements == null ) { $this->elements = (array) get_option( 'spb_elements' ); } // Just with a sort sort($this->elements); return $this->elements; }
An then the HTML I will do it with CSS content after and berfore.
!!
November 25, 2014 at 10:45 am #130844Ok great ๐
– Kyle
November 25, 2014 at 10:47 am #130847Great. Glad your sorted it.
-Rui -
Posted in: Cardinal
You must be logged in and have valid license to reply to this topic.