1

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

当我使用我的自定义模板循环访问我的自定义帖子类型时,它会获取附加的图像和摘录,但是当我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 -->
4

1 回答 1

1

找到它,我不得不从<a>标签和echo结果中删除额外的引号和连接。所以:<a href="".<?php get_permalink();?> .""> Read More > </a> 变成: <a href="<?php echo get_permalink();?>"> Read More > </a>

这让它工作了。现在,该睡觉了。

于 2013-03-10T14:33:38.960 回答