I created a custom post type(employee bio) and a custom template to display excerpts, attached images, and get the permalink to link to the custom post type.
When I use my custom template to loop through my custom post type it gets the attached image and the excerpt, but when i use get_permalink()
in the loop it returns the permalink of the page the template is used on rather than the permalink of each post it’s looping through, I exhausted so I’m probably overlooking something.
custom post type (functions.php)
add_action('init', 'employee_bio',1);
function employee_bio() {
$feature_args = array(
'labels' => array(
'name' => __( 'Employee Bios' ),
'singular_name' => __( 'Employee Bio' ),
'add_new' => __( 'Add New Bio' ),
'add_new_item' => __( 'Add New Bio' ),
'edit_item' => __( 'Edit Bio' ),
'new_item' => __( 'New Bio' ),
'view_item' => __( 'View Bio' ),
'search_items' => __( 'Search Employee Bios' ),
'not_found' => __( 'No Employee Bio found' ),
'not_found_in_trash' => __( 'No Employee Bio found in trash' )
),
'public' => true,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => true,
'has_archive' => false,
'can_export' => true,
'rewrite' => array('pages' => true, 'with_front' => false),
'menu_position' => 20,
'supports' => array('title', 'editor', 'thumbnail','excerpt', 'page-attributes','post-formats' )
);
register_post_type('bio',$feature_args);
}
custom template (bio_overview.php )
<?php get_header(); ?>
<?php $loop = new WP_Query( array( 'post_type' => 'bio') ); ?>
<div id="primary" class="content-area">
<div id="contentwide" class="site-content" role="main">
<?php while ($loop->have_posts() ) : $loop->the_post(); ?>
<div class="bio_summeries">
<div class="mini_headshot">
<?php echo the_post_thumbnail('full');?>
</div>
<p class="bio_excerpt">
<?php the_excerpt(); ?>
</p>
<a href="".<?php get_permalink();?> .""> Read More > </a>
<!--<div class="read_more_bio"></div>-->
</div>
<?php //comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
Found it, i had to remove the extra quotes and concatenation from the
<a>
tag andecho
the result. So:<a href="".<?php get_permalink();?> .""> Read More > </a>
becomes:<a href="<?php echo get_permalink();?>"> Read More > </a>
Which got it working. Now, time to get some sleep.