0

I want to show the list of childpages under a certain parent page & set how many childpages to display & show the "View More" link below the last child page displaying.

What was missing from this code(I just found it) is to display the "View More" in the last childpage of the list. The shortcode used to display is like this:

[childpages parentid="1199" display="3" show_viewmore="1"]

the show_viewmore is not yet applied.

Here is the code now:

function rsi_childpages_func($atts, $content = null){
  if($atts['length'] > 0 ){
      //maybe set a minimum length here
  }else{
      $atts['length'] = 50;
  }

  if(isset($atts['parentid']) && is_numeric($atts['parentid'])){
      //id specified by shortcode attribute
      $parent_id = $atts['parentid'];
  }else{
      //get the id of the current article that is calling the shortcode
      $parent_id = get_the_ID();
  }

  if(isset($atts['display']) && is_numeric($atts['display'])){
      $notodisplay = $atts['display'];
  }else{
      $notodisplay = 1;
  }

  if(isset($atts['show_viewmore']) && is_numeric($atts['show_viewmore'])){
      $showviewmore = $atts['show_viewmore'];
  }else{
      $showviewmore = 0;
  }

  $output = "";

  if ( $children = get_children(array(
      'post_parent' => $parent_id,
      'numberposts' => $notodisplay,
      'orderby' => 'menu_order',
      'order' => 'ASC',
      'post_type' => 'page')))
  {
      foreach( $children as $child ) {
          $title = $child->post_title;

          $link = get_permalink($child->ID);

          $title = get_the_title($child->ID);

          // OP thumbnail
          $opthumb_url = get_post_meta($child->ID, '_optimizepress_page_thumbnail', true); 
          $rsiicon = get_post_meta($child->ID, 'rsipage_icon', true); 
          $rsidate = get_post_meta($child->ID, 'rsipage_date', true); 
          $opmeta = get_post_meta($child->ID, '_optimizepress_membership', true); 

          $meta = get_post_meta($child->ID);
          $meta = $meta['_'.OP_SN.'_membership'][0];
          $meta = unserialize(unserialize($meta));

          if ($showviewmore = 1){
            $viewmore = '<a href="'. get_permalink($parent_id->ID) .'">Click here to view more of ' . get_the_title($parent_id->ID) .'</a>';
          }

          if ( empty($opthumb_url) ){
            $opthumb_url = 'http://www.memberblueprint.com/salesmastermind/op2/wp-content/themes/optimizePressTheme/lib/images/default-page-listings.png';
          }
          if ($rsiicon != 'blank') {
            $ttd = '<a href="'. $link .'" target="_blank"><img class="alignleft" src="' . $rsiicon . '" width="40" height="40" style="margin:0 5px 10px 10px!important;"/><h6 class="ttitle">'. $title .'</h6><p class="hdate">'. $rsidate .'</p></a>';
          } elseif (!empty($rsidate)) {
            $ttd = '<a href="'. $link .'" target="_blank"><h6 class="ttitle" style="margin-left: 14px;">'. $title .'</h6><p class="hdate" style="margin:0px 0px 0px 15px;">'. $rsidate .'</p></a>';
          } else { 
            $ttd = '<a href="'. $link .'" target="_blank"><h6 class="ttitle" style="margin-left: 14px;">'. $title .'</h6></a>';
          }

          $output .= '<div class="pagelisting">';
          $output .= '<div class="thumb"><a href="'. $link .'" target="_blank"><img src="'. $opthumb_url .'" alt="'. $title .'" class="" width="163"></a></div>' ;
          $output .= '<div class="content">'. $ttd .'';
                        $description = stripslashes(base64_decode($meta['description']));
                        if (strlen($description) > 140) {
                            $output .= '<p class="context">'.substr($description, 0, 140).'...</p>';
                        } else {
                            $output .= '<p class="context">'.$description.'</p>';
                        }
          $output .= '</div>';
          $output .= '<div style="clear:both;"></div></div>'  ;

      }
  } 

  return $output;
}
add_shortcode('childpages', 'rsi_childpages_func');

Problem right now, is how can show the "view more" in the last childpage in the list.

Any suggestions is greatly appreciated.

0

got it working now... I added a counter

$i = 0;    
$childnum = count($children);

just after the if statement of the children. & added this code

      if ($i == $childnum - 1) {
          $output .= '<div class="viewmore">'. $viewmore .'</div>';
      }
      $i++;

after the the code:

$output .= '<div style="clear:both;"></div></div>';

...Thanks again.. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.