Community Forums › Forums › Archived Forums › General Discussion › Display custom post types on a genesis page
Tagged: custom post types, Genesis child theme
- This topic has 2 replies, 2 voices, and was last updated 9 years, 10 months ago by octoberstone.
-
AuthorPosts
-
December 9, 2014 at 11:17 am #134090octoberstoneMember
I wish to display a list of custom post types (tenders) within the body of this page - http://www.octoberstone.co.uk/wordpress/procurement/tender-opportunities/
I have created a page template and it lists the custom post types but the rest of the page content is not displayed. I'm not sure if using a page template is the correct approach. See - http://www.octoberstone.co.uk/wordpress/procurement/tenders-list/
My child theme is put together from the Genesis theme. I have tried many ways from what snippets picked up but none are working correctly form me.
I'm a learner, not very familiar with php and have built this from code snippets from many forums. I would really appreciate any assistance.
Thanks. Tony
http://www.octoberstone.co.uk/wordpress/procurement/tender-opportunitiesDecember 10, 2014 at 10:47 am #134199anotherusernameParticipantHi Tony:
Just a heads up: It looks like you marked this topic as resolved, which means that most people are going to think that yoiu already have a solution for this problem.
If you are still seeking a solution, then you should make sure this thread is NOT marked as resolved.
Unless you DID find a solution already, in which case you should post your solution here.
December 10, 2014 at 11:04 am #134203octoberstoneMemberThanks @anotherusername I mistaking published this topic twice. Couldn't figure out how to remove. 🙂
I'm a beginner.I managed to figure out the code I required with trial and error. If anyone has a similar issue, this is what worked for me.
I would be keen to know if the code is clean and is a good solution.My custom post type is 'tenders'
I put the code below into my functions file (I actually created a function plugin)
Thanks to http://wpsmith.net/2011/custom-post-types/understanding-wordpress-custom-post-types-displaying-custom-post-types/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"><h1 class="entry-title"><a href="'.get_permalink().'" title="' . get_the_title() . '">'.get_the_title() .'</a></h1></header>'; $output .= '<p class="entry-meta">Published: <time class="entry-time" datetime="2014-11-10T10:47:44+00:00" itemprop="datePublished">'; $output .= get_the_date(); $output .= '</time></p>'; $output .= '<p>' .get_the_excerpt(); $output .= '</p>'; $output .= '<div class="tender-meta">'; $output .= '<ul><li><span class="medium">Closing date: </span>' .get_field( 'closing_date' ); $output .= '<li><span class="medium">at </span>' .get_field( 'closing_time' ); $output .= '</li></ul>'; $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');
-
AuthorPosts
- The topic ‘Display custom post types on a genesis page’ is closed to new replies.