admin管理员组文章数量:1430846
my wordpress site urls like this: /?pid=a125a5&lang=en and query of my archive page like this:
<?php
$the_slug = get_query_var('pid');
if ($the_slug){
if ( $post = get_page_by_path( $the_slug, OBJECT, 'myposttype' ) )
$id = $post->ID;
else
$id = 0;
?>
<?php get_header(); ?>
<div class="warpper">
<?php ;
$args = array(
'name' => $the_slug,
'post_type' => 'myposttype',
'post_status' => 'publish',
'numberposts' => 1,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; else: ?><?php endif; ?>
<php } else{...};
its work but commands like is_single()
return false and wordpress not showing edit post in admin bar.
my wordpress site urls like this: https://example/?pid=a125a5&lang=en and query of my archive page like this:
<?php
$the_slug = get_query_var('pid');
if ($the_slug){
if ( $post = get_page_by_path( $the_slug, OBJECT, 'myposttype' ) )
$id = $post->ID;
else
$id = 0;
?>
<?php get_header(); ?>
<div class="warpper">
<?php ;
$args = array(
'name' => $the_slug,
'post_type' => 'myposttype',
'post_status' => 'publish',
'numberposts' => 1,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; else: ?><?php endif; ?>
<php } else{...};
its work but commands like is_single()
return false and wordpress not showing edit post in admin bar.
2 Answers
Reset to default 0To show single page for your Custom Post Type
you can use single-post-type.php
file where you need to add your post type
name after single-
and use a query on this file. WordPress will use this file to show a single page of your CPT.
The is_single()
function will return always false
in the archive page template. Cause, the page is archive page template.
本文标签: custom post typesTell wordpress to show a single page instead of an archive page
版权声明:本文标题:custom post types - Tell wordpress to show a single page instead of an archive page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745567904a2663871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论