自定义帖子类型模板在循环中返回错误的永久链接

时间:2013-03-10 13:50:14

标签: wordpress custom-post-type permalinks

我创建了一个自定义帖子类型(员工简历)和一个自定义模板来显示摘录,附加图片,并获得永久链接以链接到自定义帖子类型。

当我使用自定义模板循环我的自定义帖子类型时,它会获取附加图像和摘录,但是当我在循环中使用get_permalink()时,它会返回模板用于页面的固定链接比起每个帖子的永久链接,我筋疲力尽,所以我可能会忽略一些东西。

自定义帖子类型(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);
}

自定义模板(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 -->

1 个答案:

答案 0 :(得分:0)

找到它,我必须从<a>标记和结果echo中删除多余的引号和连接。因此:<a href="".<?php get_permalink();?> .""> Read More > </a>变为:<a href="<?php echo get_permalink();?>"> Read More > </a>

哪个有效。现在,是时候睡个好觉了。