Hello all,
Resolved
I am currently trying to develop a plugin for wordpress to output three pages into one page, the reason for this is to create something like below.
I have looked around and not seen something similar to what i am wanting to do.
Below is my code & output. EDITED BELOW CODE: as according to 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' );
?>
This continues further down the page another 5/6 times.
I wondering why:
- I have multiple entry's
- They're not the pages I requested
Could anybody possibly help, fix the probelms?
Resolved
What I done:
Please feel free to manipulate below in your own answer for more efficiency or for different adaptions.