permalinks - Linking from a list of custom post type items to a single - get_post_permalink not working correctly

I have created a custom post type of Case Studies, and created a list page which gives an overview of each. Some have a

I have created a custom post type of Case Studies, and created a list page which gives an overview of each. Some have a link straight to the case study in PDF form and some have a link to a single case study view, where full text and a full size image can be seen.

The problem is with the link to the single view. When you hover over the link it shows a URL which is correct for the name of the case study, and when you click on it, the correct URL is brought up, but the content on the page is the content of a different case study.

Hope someone can help, it's driving me mad now!

This is the list page code:

<article id="content" class="projectListView">
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title('<h1>' , '</h1>'); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php $loop = new WP_Query( array( 'post_type' => 'case-study', 'category_name' => 'construction-case', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts('post_type=case-study') ) : $loop->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php if (has_post_thumbnail() ) { ?>
<div class="projectThumb left">
<?php the_post_thumbnail(); ?>
</div>
<div class="projectSummary left">
<?php the_excerpt(); ?>
<?php } else { ?>
<div class="caseStudyIcon left">
<a href="<?php the_field('upload_case_study'); ?>">&nbsp;</a>
</div>
<div class="caseStudySummary left">
<?php the_excerpt(); ?>
<?php } ?>
<?php if (get_field('upload_case_study')) { ?>
<p class="right"><a href="<?php the_field('upload_case_study'); ?>">Download <?php the_title(); ?></a></p>
<?php } else { ?>
<p class="right"><a href="<?php echo get_post_permalink(); ?>">Read more &gt;</a></p>
<?php } ?>
</div>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'blankslate' ) . '&after=</div>') ?>
<?php edit_post_link( __( 'Edit', 'blankslate' ), '<div class="edit-link">', '</div>' ) ?>
</div>
</div>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</article>

And this is the single case study page code:

<article id="content">
<?php query_posts( 'post_type=case-study' ); ?>
<?php the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<div class="projectDesc">
<?php the_content(); ?>
</div>
<?php 
if ( has_post_thumbnail() ) {
the_post_thumbnail();
} 
?>
<?php edit_post_link( __( 'Edit', 'blankslate' ), '<div class="edit-link">', '</div>' ) ?>
</div>
</div>
<?php comments_template( '', true ); ?>
</article>

The actual development site can be viewed here:

/

I have created a custom post type of Case Studies, and created a list page which gives an overview of each. Some have a link straight to the case study in PDF form and some have a link to a single case study view, where full text and a full size image can be seen.

The problem is with the link to the single view. When you hover over the link it shows a URL which is correct for the name of the case study, and when you click on it, the correct URL is brought up, but the content on the page is the content of a different case study.

Hope someone can help, it's driving me mad now!

This is the list page code:

<article id="content" class="projectListView">
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title('<h1>' , '</h1>'); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php $loop = new WP_Query( array( 'post_type' => 'case-study', 'category_name' => 'construction-case', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts('post_type=case-study') ) : $loop->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php if (has_post_thumbnail() ) { ?>
<div class="projectThumb left">
<?php the_post_thumbnail(); ?>
</div>
<div class="projectSummary left">
<?php the_excerpt(); ?>
<?php } else { ?>
<div class="caseStudyIcon left">
<a href="<?php the_field('upload_case_study'); ?>">&nbsp;</a>
</div>
<div class="caseStudySummary left">
<?php the_excerpt(); ?>
<?php } ?>
<?php if (get_field('upload_case_study')) { ?>
<p class="right"><a href="<?php the_field('upload_case_study'); ?>">Download <?php the_title(); ?></a></p>
<?php } else { ?>
<p class="right"><a href="<?php echo get_post_permalink(); ?>">Read more &gt;</a></p>
<?php } ?>
</div>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'blankslate' ) . '&after=</div>') ?>
<?php edit_post_link( __( 'Edit', 'blankslate' ), '<div class="edit-link">', '</div>' ) ?>
</div>
</div>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</article>

And this is the single case study page code:

<article id="content">
<?php query_posts( 'post_type=case-study' ); ?>
<?php the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<div class="projectDesc">
<?php the_content(); ?>
</div>
<?php 
if ( has_post_thumbnail() ) {
the_post_thumbnail();
} 
?>
<?php edit_post_link( __( 'Edit', 'blankslate' ), '<div class="edit-link">', '</div>' ) ?>
</div>
</div>
<?php comments_template( '', true ); ?>
</article>

The actual development site can be viewed here:

http://wp.perfect-image.co.uk/construction/construction-case-studies/

Share Improve this question edited Nov 14, 2012 at 17:43 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 14, 2012 at 17:11 rachelrachel 1
Add a comment  | 

1 Answer 1

Reset to default 0

In your second code block (single case study), you're overriding the main query:

<?php query_posts( 'post_type=case-study' ); ?>

Get rid of it!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745270883a4619738.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信