I need help with 2 Custom Post Types. I have two plugins Custom Post Type UI and Advanced Custom Fields, in use with 3 clicks template. I’ve created two different post types and associated fields with ACF. These are fine on the WP admin. I need to configure the php so they appear on the front-end.
Post type 1 (keynote speakers) fields: (repeater field name:speaker_details) name, picture and biography fields (biography on left and image on right)
Post type 2 (event programme) fields: (Repeater field: event_programme) date, (repeater field: event_details) start_time, title, speaker, location, event_type.
Some events run parallel and i'd like to color code them and make them responsive something like https://mwf.ucla.edu/conference/index.php?schedule/
I can do the css, I just need the 2 templates and any extras that need to go into the functions.php file (I presume!). This is going to a client so it has to be intuitive to use in the admin.
I dupicated one of the templates which has section navigation on the right (which I want to keep). This is what I was trying to create for the keynote speakers cpt (but nothing shows up in the front end and I know I'm missing repeater field and other stuff).
<?php
/**
*
* The navigation block is after the main content for SEO purposes.
* This will be fixed via CSS rules.
*
* For the full license information, please view the Licensing folder
* that was distributed with this source code.
*
* @package G1_Framework
* @subpackage G1_Theme03
* @since G1_Theme03 1.0.0
*/
// Prevent direct script access
if ( !defined('ABSPATH') )
die ( 'No direct script access allowed' );
?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
global $post;
$elems = G1_Elements()->get();
$title = $elems[ 'title' ] ? the_title( '', '', false ) : '';
$subtitle = wp_kses_data( get_post_meta( $post->ID, '_g1_subtitle', true ) );
?>
<?php if( strlen( $title ) || strlen( $subtitle ) ): ?>
<header class="entry-header">
<div class="g1-hgroup">
<?php if ( strlen( $title ) ): ?>
<h1 class="entry-title"><?php echo $title; ?></h1>
<?php endif; ?>
<?php if ( strlen( $subtitle ) ): ?>
<h3 class="entry-subtitle"><?php echo $subtitle; ?></h3>
<?php endif; ?>
</div>
</header><!-- .entry-header -->
<?php endif; ?>
<!-- BEGIN .entry-content -->
<div class="entry-content">
<?php the_content(); ?>
<?php g1_wp_link_pages(); ?>
<div><?php get_sub_field('name'); ?></div>
<div><?php get_sub_field('picture'); ?></div>
<div>
<?php get_sub_field('biography'); ?></div>
</div>
<!-- END .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'g1_theme' ), '<span class="edit-link">', '</span>' ); ?>
</footer>
<?php comments_template( '', true ); ?>
</article><!-- #post-<?php the_ID(); ?> -->
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
The template for the Event Programme is the same as above. I can supply other files if needed. Thanks!
Arnav Joy answers:
try this
<?php
/**
*
* The navigation block is after the main content for SEO purposes.
* This will be fixed via CSS rules.
*
* For the full license information, please view the Licensing folder
* that was distributed with this source code.
*
* @package G1_Framework
* @subpackage G1_Theme03
* @since G1_Theme03 1.0.0
*/
// Prevent direct script access
if ( !defined('ABSPATH') )
die ( 'No direct script access allowed' );
?>
<div id="primary">
<div id="content" role="main">
<?php query_posts('post_type=keynote_speakers&posts_per_page=-1'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
global $post;
$elems = G1_Elements()->get();
$title = $elems[ 'title' ] ? the_title( '', '', false ) : '';
$subtitle = wp_kses_data( get_post_meta( $post->ID, '_g1_subtitle', true ) );
?>
<?php if( strlen( $title ) || strlen( $subtitle ) ): ?>
<header class="entry-header">
<div class="g1-hgroup">
<?php if ( strlen( $title ) ): ?>
<h1 class="entry-title"><?php echo $title; ?></h1>
<?php endif; ?>
<?php if ( strlen( $subtitle ) ): ?>
<h3 class="entry-subtitle"><?php echo $subtitle; ?></h3>
<?php endif; ?>
</div>
</header><!-- .entry-header -->
<?php endif; ?>
<!-- BEGIN .entry-content -->
<div class="entry-content">
<?php the_content(); ?>
<?php g1_wp_link_pages(); ?>
<?php if( get_field('speaker_details') ): ?>
<?php while( has_sub_field('speaker_details') ): ?>
<div><?php the_sub_field('name'); ?></div>
<div><?php the_sub_field('picture'); ?></div>
<div> <?php the_sub_field('biography'); ?></div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<!-- END .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'g1_theme' ), '<span class="edit-link">', '</span>' ); ?>
</footer>
<?php comments_template( '', true ); ?>
</article><!-- #post-<?php the_ID(); ?> -->
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
Arnav Joy comments:
in above code you have to change following:-
1. in following line
<?php query_posts('post_type=keynote_speakers&posts_per_page=-1'); ?>
i have used post type as "keynote_speakers" so you have to change that with your post type .
2. in following lines
<?php if( get_field('speaker_details') ): ?>
<?php while( has_sub_field('speaker_details') ): ?>
<div><?php the_sub_field('name'); ?></div>
<div><?php the_sub_field('picture'); ?></div>
<div> <?php the_sub_field('biography'); ?></div>
<?php endwhile; ?>
<?php endif; ?>
you have to change name of the repeater field in following lines
<?php if( get_field('speaker_details') ): ?>
<?php while( has_sub_field('speaker_details') ): ?>
and name of the sub field in following
<div><?php the_sub_field('name'); ?></div>
<div><?php the_sub_field('picture'); ?></div>
<div> <?php the_sub_field('biography'); ?></div>
let me know if you have any problem doing that .