我想显示某个父页下的子页列表(&M);设置要显示的子页面数(&P);在显示的最后一个子页面下方显示“查看更多”链接。
这段代码(我刚刚找到)缺少的是在列表的最后一个子页面中显示“查看更多”。用于显示的短代码如下所示:
[childpages parentid="1199" display="3" show_viewmore="1"]
the
show_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\');
现在的问题是,如何在列表的最后一个子页面中显示“查看更多”。
非常感谢您的任何建议。