Forums

Single Custom Post Type (9 posts)

  1. hoss9009
    Member
    Posted 2 years ago #

    So I can't find specific code to pull a single-customposttype.php
    I can create a page of custom posts, but don't know how create a special, single custom post page.

    What am I missing?
    Ideas?

  2. hoss9009
    Member
    Posted 2 years ago #

    Perhaps an example loop?

  3. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    I've not tried this myself, so can't be 100% sure but I thought you could just use the same basic Loop as you use in single.php. It's the template heirarchy that does all of the work by selecting the correct template file. So the only Loop adjustments that you need to make are those where you want a slightly different display. Within the Loop itself, you're still just dealing with $post - same as single.php

  4. hoss9009
    Member
    Posted 2 years ago #

    hmmm... so just copy my single.php with the custom post type name?

  5. hoss9009
    Member
    Posted 2 years ago #

    jus tried that... no luck.
    here's my single:

    <?php get_header(); ?>
    <div id="content">
    <div id="red-news" onclick="location.href='<?php echo get_option('home'); ?>/news/';" style="cursor:pointer;"></div>
    <div id="left">
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_url'); ?>/js/demoStyles.css">
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_url'); ?>/js/jScrollPane.css">
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery_002.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jScrollPane.js"></script>
    <script type="text/javascript">
    
    			$(function()
    			{
    				$('#single-entry').jScrollPane({showArrows:true});
    			});
    
    		</script>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2 class="single-title"><?php the_title(); ?></h2>
    <div class="single-date"><span class="month"><?php the_time('M') ?></span><span class="day"><?php the_time('j') ?></span><span class="year"><?php the_time('Y') ?></span></div>
    <div class="single-category"><?php the_category(', ') ?></div>
    <div class="clear"></div>
    <div tabindex="0" style="height: 560px; width: 540px; " class="jScrollPaneContainer jScrollPaneScrollable">
    <div class="single-entry " id="single-entry">
    <?php the_content(); ?>
    </div><!-- end .single-entry & #single-entry -->
    </div><!-- end jScroll wrap div -->
    <?php endwhile; ?>
    <?php else : ?>
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    <div class="clear"></div>
    </div><!-- end id="left" -->
    
    <?php include (TEMPLATEPATH . '/news-sidebar.php'); ?>
    <div class="clear"></div></div><!-- end "content -->
    <?php get_footer(); ?>
  6. Anna-Maria Eriksson
    Member
    Posted 2 years ago #

    I have a tutorial on that that can help you (I hope).

    http://greatdanemaniac.com/tutorials-2/

  7. hoss9009
    Member
    Posted 2 years ago #

    Thanks! I'll give it a whirl.

  8. hoss9009
    Member
    Posted 2 years ago #

    Ok... here's something thrown into the mix with ECPT.

    I just realized that I have my CPT being called on a child page:
    domain.com/parent/child/

    I'm wanting to have the singe-posttype.php come up as:
    domain.com/parent/child/single-posttype/

    BUT... it's coming up as:
    domain.com/child/single-posttype/

    Also, the ECPT's "System Key" (for this particular CPT) is the same as my child page. I changed the "System Key" and am actually getting:
    domain.com/systemkey/single-posttype/
    but still no single-posttype.php comes up.

    Any ideas on how to fix all this?
    1. How do I get the single-posttype.php to work?
    2. How do I do all this with the "Pretty URL's" working?

    BTW, thanks for everyone's help.

  9. curtisblackwell
    Member
    Posted 2 years ago #

    There's probably a better way to do this, but this does work:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<?php $postid = get_the_ID(); ?>
    <?php endwhile; endif; ?>
    
    <?php query_posts( array(
    	'p' =>  $postid,
    	'post_type' => '_cpb_locations'
    ) ); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	[insert your code here]
    
    <?php endwhile; endif; ?>

    I only know a little bit of php and I'm not all that familiar with WordPress code, but it seems there'd be a better way to do this. This has an extra loop just to get the current posts ID and assign it a variable for the desired query.

    Hope this helps if you haven't already figured it out (I see it's been 6 months…).

    p.s. You'll want to replace _cpb_locations with whatever you called your custom post type in functions.php.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.