Community Forums › Forums › Archived Forums › General Discussion › Display custom post types with a page
Tagged: custom post types, shortcodes
- This topic has 3 replies, 3 voices, and was last updated 9 years, 8 months ago by octoberstone.
-
AuthorPosts
-
December 10, 2014 at 9:09 am #134155octoberstoneMember
Hi
I wish to display a list of my custom post types (tenders) within the page content of this page - http://www.octoberstone.co.uk/wordpress/procurement/tender-opportunities/It should display:
Post title as link
Meta data
part of post with more link
custom fields
See: http://www.octoberstone.co.uk/wordpress/tenders/I have tried using a page template but it displays the list without the other page content - See: http://www.octoberstone.co.uk/wordpress/procurement/tenders-list/
I've also tried shortcode (See - http://www.octoberstone.co.uk/wordpress/procurement/tenders-shortcode/). I am not very good at php and so I'm failing miserably to configure correctly.
My theme is a child theme created from the Genesis theme. I would really appreciate any assistance or pointers.
http://www.octoberstone.co.uk/wordpress/tenders/December 12, 2014 at 7:47 am #134367Brad DaltonParticipantYou could create a new WP_Query
http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
And then create a shortcode with the function.
December 12, 2014 at 12:03 pm #134396DTHkellyMemberSome non-coding options:
https://wordpress.org/plugins/custom-content-shortcode/or Content Views
Free
Premium
http://www.contentviewspro.com/pricing/?utm_source=sampleJanuary 27, 2015 at 4:50 am #138740octoberstoneMemberMany thanks for your suggestions. I tried your suggestion Braddalton but I got lost - however it did help me understand how things worked and so I was able to refine my search and found the following which worked. The short code to be placed in my page is [Tenders]
I found it here: http://wpsmith.net/2011/custom-post-types/understanding-wordpress-custom-post-types-displaying-custom-post-types/
[PHP]function wps_tenders_posting() {
global $post;
$xglobals = $GLOBALS;
$args = array( 'post_type' => 'tenders' , 'posts_per_page' => 10 , 'orderby' => 'post_title' , 'order' => 'ASC' );
$tendersloop = new WP_Query( $args );
if ( $tendersloop->have_posts() ) {
while ( $tendersloop->have_posts() ): $tendersloop->the_post();
$output .= '<div id="tenders-content">';
$output .= '<header class="entry-header"><h3 class="tender-title">'.get_the_title() .'</h3></header>';
$output .= '<p class="entry-meta">Published: <time class="entry-time" itemprop="datePublished">';
$output .= get_the_date();
$output .= '</time></p>';
$output .= '<p>' .get_the_excerpt();
$output .= '</p>';
$output .= '<div class="tender-meta">';
$output .= '- <span class="medium">Closing date: </span>' .get_field( 'closing_date' );
$output .= ' - <span class="medium">at </span>' .get_field( 'closing_time' );
$output .= '
';
$output .= '</div></div>';
endwhile;
}
else
$output = '<p>No tenders were found.</p>';
$GLOBALS = $xglobals;
return $output;
}function my_init() {
add_shortcode( 'tenders' , 'wps_tenders_posting' );
}add_action('init' , 'my_init');
[/PHP] - <span class="medium">Closing date: </span>' .get_field( 'closing_date' );
-
AuthorPosts
- The topic ‘Display custom post types with a page’ is closed to new replies.