working create custom wordpress theme custom post types:
i have added custom post types (via plugin custom post ui) , custom fields (via advanced custom fields). custom post correctly displaying in new template page created (single-custom.php). individual custom posts displaying like.
the problem on homepage title displaying.
what i've done:
1) i've added following code allow new post types pulled feed on homepage/blog feed via functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( ( is_home() && $query->is_main_query() ) || is_feed() ) $query->set( 'post_type', array( 'post', 'custom' ) ); return $query;
thanks justin tadlock this
2) i've created custom content page content-custom.php , amended index loop call template:
<?php if ( have_posts() ) : ?> <?php /* start loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'custom', get_post_format() ); ?> <?php endwhile; ?>
my homepage still displaying titles of custom posts , not full content hope. problem has call of the_content in content-custom.php can't find issue still familiarizing myself wordpress. relevant code content-custom.php follows:
<article id="post-<?php the_id(); ?>" <?php post_class(); ?>> <header class="entry-header"> //the title below displayed correctly <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1> </header><!-- .entry-header --> // problem begins below. entry-content div created empty , not pulling content custom post through the_content call. <div class="entry-content"> <?php the_content(); ?> </div><!-- .entry-content -->
i not familiar plugins mentioned, check if custom post type has "content" field.
if "content" custom field have with
get_post_meta($post->id, 'field name', true);
i had similiar problem , fixed adding following template. can try adding content-custom.php:
<?php wp_reset_postdata(); ?>
Comments
Post a Comment