• I’m looking at a website for a client who wants to add a new page into a list on the homepage. The site was designed by a previous designer.

    I’m stumped on how it’s functioning. I googled the shortcodes and found references via wordpress.com but they all referenced that the child pages of the parent would be listed and in this case, these pages are all parents – no child pages.

    On the homepage, the following shortcode is displaying a list of courses:
    —————————————————-
    [child-list parent=’courses’]
    —————————————————-

    The courses which all show up in this area do NOT have a parent page. I have looked through the code and found the following in functions.php.
    —————————————————-

    function child_list($atts,$content = null){
    	extract(shortcode_atts(array(
    		'parent' => '',
    	), $atts));
    	ob_start();
    	$page = get_page_by_title($parent);
    	$pageID = $page->ID;
    	$args = array('post_type'=>'page','order'=>'ASC','post__in' => array(50,60,78,80,67,63));
    	$loop = new WP_Query($args);
    	echo '<div id="child-list">';
    	while ($loop->have_posts()) : $loop->the_post();
    		echo '<div class="child-list-wrap">';
    		if ( has_post_thumbnail() ) {
    			the_post_thumbnail('course-img');
    		} else {
    			echo '<div class="no-thumb">No<br> Thumb</div>';
    		}
    		echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
    		echo '</div>';
    	endwhile;
    	echo '</div>';
    	wp_reset_query();
    	$output = ob_get_clean();
    	return $output;
    }
    add_shortcode('child-list','child_list');

    —————————————————-

    How are the course pages to be included being defined???? I even duplicated an existing course page and it was not added automatically so I need to find where/how these are defined. Any help is greatly appreciated.

    • This topic was modified 3 years, 5 months ago by t-p. Reason: Moved to Fixing WordPress, this is not Everything else WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The thumbnails output belong to pages with IDs 50,60,78,80,67,63. (part of the $args array). It has nothing to do with children. The shortcode was modified from one that would list children to instead list these specific pages.

    To restore child functionality, replace
    'post__in' => array(50,60,78,80,67,63)
    with
    'post_parent' => $pageID

    If this site is indeed a self-hosted wordpress.org site, which I believe it is, you should avoid looking in wordpress.com for documentation. While there is a lot of commonality, there is enough difference for .com docs to be not applicable and just be confusing.

    Thread Starter beltanconsultancy

    (@thetraininglady)

    Thank you yes that makes sense now.
    I’ve added the page ID into the array as needed and that has worked.
    This is a self-hosted .org site so I knew the .com documentation was not applicable but it pointed me in the right direction.

    Only thing I need to do it change the order to show in the order the page IDs are listed in the array. I tried changing the order to orderby and use ‘ID’ but it didn’t work.

    Any tips on this?

    Thread Starter beltanconsultancy

    (@thetraininglady)

    I want the pages to display in this order by ID: 50,63,5851,67,78,80

    Moderator bcworkz

    (@bcworkz)

    You need both order and orderby because the default order is DESC
    'order'=>'ASC', 'orderby'=>'ID',
    This will yield ordering like 50,51,58,63,67,78,80, not really like your example. To get ordering that’s not straight up or down, you’d need a custom sorting algorithm used by PHP’s usort().

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How is this shortcode working?’ is closed to new replies.