I have many child galleries organized by their parent galleries (multiple parent galleries with several child galleries under).
I would like to create a shortcode that is able to query all the child galleries under a specified parent gallery. I'm having a bit of difficulty... anyone care to help me out?
This is the function that I have so far:
function display_gallery_cards($atts) {
global $post;
$defaults = array(
'sort_column' => menu_order,
'title_li' => '',
'child_of' => '',
'depth' => 1,
'echo' => 0,
'parentgal' => '',
'walker' => new Thumbnail_walker()
);
$args = wp_parse_args( $args, $defaults );
$childpages = wp_list_pages(array(
'sort_column' => menu_order,
'title_li' => '',
'child_of' => $args['parentgal'],
'depth' => 1,
'echo' => 0,
'walker' => new Thumbnail_walker()
));
if ( $childpages ) {
$string = '<ul class="two-columns">' . $childpages . '</ul><div class="clearfix"></div>';
}
return $string;
}
add_shortcode( 'list-cards', 'display_gallery_cards' );
When I do [list-cards parentgal='941'] the output displays fine, but it's displaying the wrong pages. Am I passing on the "parent gallery" post ID correctly?
$parentgal
variable doesn't exist. As far as I can tell in your given functions code you're not doing anything with the passed$atts
variable either. I suggest checking out thewp_parse_args()
function. and edit your question ( using the edit link above ) to update your functions code.941
you don't see the subpage that belong under page id941
?