first theme commit
This commit is contained in:
78
includes/helper_functions.php
Normal file
78
includes/helper_functions.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Helper functions.
|
||||
*
|
||||
* @package ThemeStarter
|
||||
*/
|
||||
|
||||
// Get List of Sub Categories for Slug
|
||||
function getSubpagesForSlug($arrayOfWPPages, $slug)
|
||||
{
|
||||
foreach ($arrayOfWPPages as $page) {
|
||||
if ($page['page']->post_name === $slug) {
|
||||
return $page['subpages'];
|
||||
}
|
||||
}
|
||||
// Return an empty array if the slug is not found
|
||||
return [];
|
||||
}
|
||||
|
||||
// Return WordPress Page For A Slug
|
||||
function getPageForSlug($arrayOfWPPages, $slug)
|
||||
{
|
||||
foreach ($arrayOfWPPages as $page) {
|
||||
if ($page['page']->post_name === $slug) {
|
||||
return $page['page'];
|
||||
}
|
||||
|
||||
foreach ($page['subpages'] as $index => $subpage) {
|
||||
if ($subpage->post_name === $slug) {
|
||||
|
||||
return $page['subpages'][$index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return an empty array if the slug is not found
|
||||
return [];
|
||||
}
|
||||
|
||||
function ddd($variable)
|
||||
{
|
||||
echo '<pre>';
|
||||
var_dump($variable);
|
||||
echo '<pre>';
|
||||
}
|
||||
|
||||
// Get An Array of Top Level Pages and their Subpages
|
||||
function get_pages_as_array()
|
||||
{
|
||||
|
||||
$args = [
|
||||
'sort_order' => 'ASC',
|
||||
'sort_column' => 'menu_order',
|
||||
'hierarchical' => 1,
|
||||
'exclude' => [237, 238]
|
||||
];
|
||||
|
||||
$pages = get_pages($args);
|
||||
$page_hierarchy = array();
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$parent_id = $page->post_parent;
|
||||
|
||||
// If it's a top-level page
|
||||
if ($parent_id == 0) {
|
||||
$page_hierarchy[$page->ID] = array(
|
||||
'page' => $page,
|
||||
'subpages' => array()
|
||||
);
|
||||
} else {
|
||||
// If it's a child page, add it under its parent
|
||||
$page_hierarchy[$parent_id]['subpages'][] = $page;
|
||||
}
|
||||
}
|
||||
|
||||
return $page_hierarchy;
|
||||
}
|
Reference in New Issue
Block a user