Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NickDeckerDevs/6b8bc9b3c73ecefb233147cedf5f4ad0 to your computer and use it in GitHub Desktop.

Select an option

Save NickDeckerDevs/6b8bc9b3c73ecefb233147cedf5f4ad0 to your computer and use it in GitHub Desktop.
displaying all the data center menu on the data center page. does a page search and walks through it
<?php
function display_data_centers( $atts, $content ) {
$values = shortcode_atts( array(
// not being used, is in the CSS
// 'columns' => $atts[ 'columns' ],
), $atts );
$html = '<div class="data-center-links auto"><div>';
$state_pages = get_pages( [
'parent' => 93,
'sort_order' => 'ASC',
'sort_column' => 'post_name'
] );
foreach( $state_pages as $state ) {
$html .= '<h4>' . $state->post_title . '</h4><ul>';
$city_pages = get_pages( [
'parent' => $state->ID,
'sort_order' => 'ASC',
'sort_column' => 'post_name'
] );
foreach( $city_pages as $city ) {
$html .= '<li><a href="' . get_permalink( $city->ID ) . '">' . $city->post_title . '</a></li>';
}
$html .= '</ul>';
if( $state->post_title == 'Maryland' || $state->post_title == 'New York' || $state->post_title == 'Pennsylvania' || $state->post_title == 'Wisconsin' ) {
if( $state->post_title != 'Wisconsin' ) {
$html .= '</div><div>';
} else {
$html .= '</div>';
}
}
}
$html .= '</div>';
return $html;
}
add_shortcode( 'display_data_centers', 'display_data_centers' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment