Tagged: content-extensions.php, custom-fields, custom-post-type, display, single
- This topic has 2 replies, 2 voices, and was last updated 10 years, 8 months ago by Sanjip Shah.
-
AuthorPosts
-
February 26, 2014 at 10:20 am #8123biringoParticipant
Good morning everybody!
I’ve created a child theme from Attitude free and have some doubts and troubles on how to use custom posts and custom fields.
I’m using “Advanced Custom Fields” plugin for create the custom fields assigned to each custom post type. Thought I use “Miniloops” plugin for displaying diferent list of recent posts I have no problem with the “Archive view” but I don’t know how to load the different custom fields in the Single view.I’ve copied the “content-extensions.php” in the child folder and hack a little bit of code with no results. So, someone can help me?
Thanks in advance!
February 27, 2014 at 10:48 am #8162biringoParticipantSince nobody respond on this thread, I’m going to explain what I’m trying to do.
This theme relay hard on wordpress hooks. The template files in the main theme directory aren’t useful for modifying the template behaviour if we don’t modify the files contained in ‘/library/estructure/’ too. In “content-extensions.php” we can find different functions which define how each template will display its content.
For example, here the function which describes the “simple post template”. I add some comments describing better my aproach for displaying “custom-fields”:
if ( ! function_exists( 'attitude_theloop_for_single' ) ) : /** * Fuction to show the single post content. */ function attitude_theloop_for_single() { global $post; /*First, I've tried to filter here for custom-post-type */ if( have_posts() ) { while( have_posts() ) { the_post(); do_action( 'attitude_before_post' ); ?> <section id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <article> <?php do_action( 'attitude_before_post_header' ); ?> <header class="entry-header"> <h2 class="entry-title"> <?php the_title(); ?> </h2><!-- .entry-title --> </header> <?php do_action( 'attitude_after_post_header' ); ?> <?php do_action( 'attitude_before_post_content' ); ?> <div class="entry-content clearfix"> <?php the_content(); /* Add here the "custom-fields" needed. /* Note that I use a conditional, but this solution doesn't work. if ( is_single() && post_type == "consulta" ) { the_field('resposta'); the_leaflet_field( 'localitzacio' ); ?> } <?php if( is_single() ) { $tag_list = get_the_tag_list( '', __( ', ', 'attitude' ) ); if( !empty( $tag_list ) ) { ?> <div class="tags"> <?php _e( 'Tagged on: ', 'attitude' ); echo $tag_list; ?> </div> <?php } } wp_link_pages( array( 'before' => '<div style="clear: both;"></div><div class="pagination clearfix">'.__( 'Pages:', 'attitude' ), 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', 'pagelink' => '%', 'echo' => 1 ) ); ?> </div> <div class="entry-meta-bar clearfix"> <div class="entry-meta"> <span class="by-author"><?php _e( 'By', 'attitude' ); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a></span> | <span class="date"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span> | <?php if( has_category() ) { ?> <span class="category"><?php the_category(', '); ?></span> | <?php } ?> <?php if ( comments_open() ) { ?> <span class="comments"><?php comments_popup_link( __( 'No Comments', 'attitude' ), __( '1 Comment', 'attitude' ), __( '% Comments', 'attitude' ), '', __( 'Comments Off', 'attitude' ) ); ?></span> | <?php } ?> </div><!-- .entry-meta --> </div> <?php do_action( 'attitude_after_post_content' ); do_action( 'attitude_before_comments_template' ); comments_template(); do_action ( 'attitude_after_comments_template' ); ?> </article> </section> <?php do_action( 'attitude_after_post' ); } } else { ?> <h1 class="entry-title"><?php _e( 'No Posts Found.', 'attitude' ); ?></h1> <?php } } endif;
What do you think? Is this the piece of code which I need to modify?
February 28, 2014 at 8:08 am #8201Sanjip ShahParticipant@biringo This is pluggable function which means you can copy all the function to the child theme’s functions.php file and make your changes there.
Code to be added in the child themefunction attitude_theloop_for_single() { // Copy all code and make your changes as you need }
-
AuthorPosts
- You must be logged in to reply to this topic.