admin管理员组文章数量:1418025
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'); ?>"> </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 ></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'); ?>"> </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 ></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 11 Answer
Reset to default 0In your second code block (single case study), you're overriding the main query:
<?php query_posts( 'post_type=case-study' ); ?>
Get rid of it!
版权声明:本文标题:permalinks - Linking from a list of custom post type items to a single - get_post_permalink not working correctly 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745270882a2650883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论