【发布时间】:2015-06-08 08:53:25
【问题描述】:
大家好,
已解决
我目前正在尝试为 wordpress 开发一个插件,将三页输出到一页中,这样做的原因是创建如下所示的内容。
我环顾四周,没有看到与我想做的类似的事情。
以下是我的代码和输出。 编辑以下代码:根据 Pieter Goosen 的说法
<?php
function page_list( $atts ) {
//extracting input parameters (attributes of shortcode)
shortcode_atts( array(
'pages' => ''
), $atts );
/***************************************************Out***********************************************************/
$i = '';
// Get the page id by the page name
$page_names = explode(",", $atts['pages']);
foreach($page_names as $page_name) {
$page = get_page_by_title( ''.$page_name.'', OBJECT, 'page' );
//argument it
$args = array(
'post_type' => 'page',
'posts_per_page' => 3,
'page_id' => ''.$page->ID.''
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
$i .= '<div class="page-information">';
$i .= '<div class="page-information-color">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$i .= '<div class="page-information-widget" style="padding-left: 20px;">';
$i .= '<div><a href="'.get_permalink( $the_query->ID).'"><img class="alignnone size-medium wp-image-81" src="'.wp_get_attachment_url( get_post_thumbnail_id($the_query->ID,'thumbnail') ).'" alt="" width="auto" height="70" /></a></div>';
$i .= '<div><h4>'.get_the_title().'</h4></div>';
$i .= '<div> '.wp_trim_words( get_the_excerpt(), 19, '...').' </div>';
$i .= '<div><a href="'.get_permalink( $the_query->ID).'"><button class="news-widget-button" type="button">More info ></button></a></div>';
$i .= '</div>';
}
$i .= '</div>';
$i .= '</div>';
} else {
echo 'No Pages Found! :(';
}
/* Restore original Post Data */
wp_reset_postdata();
}
//returning the output to page
return $i;
}
//instantiate the shortcode
add_shortcode( 'list_pages', 'page_list' );
?>
这会在页面下方继续向下移动 5/6 次。
我想知道为什么:
- 我有多个条目
- 它们不是我请求的页面
有人可以帮忙解决问题吗?
【问题讨论】: