SLB: Notes – Admin: Creating Pages

By Sol in Lab

Relationships

  • Menu
    • Page
      • Section
      • Section
    • Page
      • Section

Data Structure (Options)

    1. Separate Elements
      • Each element types’ items are stored in a separate array
        • Menus, Pages, Sections
      • Array items contain properties for item
        • Including relationship data (parent name, etc.)
      • Relationship data not 2-way
        • Only child contains reference to parent
        • Easier to manage/change relationship of item (don’t need to know existing relationship to make change)
        • Eliminates duplicate data issues
      • Examples
        • Menu
          • Title
          • Name
          • Position (In main navigation)
        • Page
          • Title
          • Name
          • Parent (Menu)
          • Position (in menu sublist)
        • Section
          • Title
          • Name
          • Parent (Page)
          • Position (in page)
      • + Simple to change item relationships
      • + Simple to target specific element
      • - Building items requires iteration through entire child array to find all child elements
    2. Single variable for all data
      • Multidimensional array to store all menu data (Menus, Pages, Sections)
      • Example
        $menu['test'] = array (
        	'pages'		=> array (
        		'page1'		=> array (
        			'sections'	=> array (
        				'section1'	=> array ([properties]),
        				'section2'	=> array ([properties]),
        				'section3'	=> array ([properties])
        			)
        		)
        	)
        )
      • - Very deep array (lots of complexity for simple data)
      • + Organized
      • + Array defined by array structure
      • + Simple to retrieve sections of a page
      • - Must know current section parent to modify (e.g. change parent, etc.)
        • ? Better to iterate over all items in each request or iterate all items to find section for modification?
          • Will definitely need to know relationships for every request
        • + Not likely to happen very often in single request
      • - Potential for multiple sections with same name (should be unique)
        • ? Issue?
      • + Single array instead of multiple
      • - Cannot target specific child items (sections) without knowing relationship
        • Simpler to target using name
    3. Map-based
      • Separate arrays for each element type and using map to define relationships between items
      • Example
        $sections = array (
        	'section_1'	=> array (
        		'parent'	=> 'test_page'
        	)
        );
        $map['sections']['section_1'] = 'test_page';
        $map['pages']['test_page']['sections'][] = 'section_1';
      • - Multiple locations of relationship data
        • Need to adjust both when changing relationship
          • Remove old relationship from map before updating relationship
      • + Easy to build menus from top-down (Menu > Page > Section)
    4. Separate + References
      • Separate arrays for different element types and use references for 2-way relationships
      • + Uses existing objects to contain relationships
        • No need for mapping data
      • ? References necessary?
        • Could just use item name (will be using anyway)
        • A One less step to fetch child properties
      • Methodology
        • Add relationship
          $section['parent'] = {parent_name};
          $page['sections'][{section_name}] =& $section
        • Remove relationship
          unset($page['sections'][{section_name}]);
          $section['parent'] = NULL
        • Build
          • Iterate through sections (bottom > top)
            • Use WP functions to add sections/pages/menus
          • Fetch parent data to register setting
          • Iterate through remaining pages/menus and add them

Element Properties

Menu

  • Name
  • Title
  • Position/Priority

Page

  • Name
  • Title
  • Navigation Title
  • Menu (parent)
  • Callback
  • Options
  • Position/Priority

Section

  • Name
  • Title
  • Page (parent)
  • Callback
  • Options
  • Position/Priority

Building (Options)

  1. Top to Bottom
    • Start with Menus and work down to Sections