如何在我的页面显示上显示更多的视图快捷代码

时间:2015-05-06 作者:Kiko Lolo

我想显示某个父页下的子页列表(&M);设置要显示的子页面数(&P);在显示的最后一个子页面下方显示“查看更多”链接。

这段代码(我刚刚找到)缺少的是在列表的最后一个子页面中显示“查看更多”。用于显示的短代码如下所示:

[childpages parentid="1199" display="3" show_viewmore="1"]
theshow_viewmore 尚未应用。

下面是代码:

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\');
现在的问题是,如何在列表的最后一个子页面中显示“查看更多”。

非常感谢您的任何建议。

1 个回复
SO网友:Kiko Lolo

现在开始工作了。。。我加了一个计数器

$i = 0;    
$childnum = count($children);
就在孩子们的if声明之后&;添加了此代码

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

$output .= \'<div style="clear:both;"></div></div>\';
。。。再次感谢……)

结束

相关推荐

Excerpt for pages not showing

我正在创建一个简单的wordpress主题,需要页面摘录。我已经尝试了许多主题的代码,其中一些是在wordpress SO上解决的,但没有任何效果。因为我从头创建了主题,所以添加了一个空白函数。php文件,并将以下代码放入其中。add_action( \'init\', \'my_add_excerpts_to_pages\' ); function my_add_excerpts_to_pages() { add_post_type_support( \'page\', \'ex