ThemeShaper Forums » Thematic


Create a custom single.php

(9 posts)
  • Started 5 years ago by kbkisan
  • Latest reply from AnotherAndrew
  • This topic is resolved
  1. kbkisan

    Hi there,

    I've been sitting in front of the computer for 8 hours straight now to try to figure out how to create a custom [strong]single.php[/strong] page.

    What I have done is to take a javascript slideshow gallery and integrate it into Wordpress with custom fields for the images, to be able to show a slideshow within a post.. So what I basically want to do is to "check if there is a slideshow present (by verifying if there is content in the first custom field), and then I want to display the single post as follows.

    If there is a slideshow I want to show the page like this:

    - Post Title
    - Entry Meta
    - Slide Show
    - Post Content
    - Entry Utility

    And if there is no slideshow then I want to show it like this:

    - Post Title
    - Entry Meta
    - Post Content
    - Entry Utility

    The code I have managed to build so far inside the single.php is like this:

        // calling the header.php
        // action hook for placing content above #container
    <div id="container">
    	<div id="content">
    		<!-- Start the Loop. -->
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    		// call the function in our functions.php file
    		bd_parse_post_variables();  // TO ACCESS VARIABLES FROM THE CUSTOM FIELDS
    		// these variables are now available:
    		// $post_var
    		// $post_images and $post_images_label
    		// $post_links and $post_links_label
    		// $post_files and $post_files_label
    	global $post;
    	$postimageurl = get_post_meta($post->ID , 'image1', true);  // To see if there is something in the custom field 'image1'
    	//if there is then print out the post title, entry meta and content
    	if ($postimageurl) {?>
       		<h1 class="entry-title"><?php echo __((get_the_title($post->ID))); ?></h1>
        	<div class="entry-meta"><a href="#">meta</a></div>
    			<!-- Display the Post's Content in a div box. -->
    		<div class="entry-content">
    			<!-- Display our Custom Field -->
    			<div id="photos" class="galleryview">
    			<?php while(count($post_images) > 0): ?>
    				<div class="panel">
     				<img src="<?php echo array_shift($post_images); ?>" />
      				<div class="panel-overlay"></div>
    			<?php endwhile; ?>
    		<?php echo __((the_excerpt())); ?>
    <?php // if there is nothing in the field then print out the normal post ?>
        <?php } else { ?>
        <?php // action hook creating the single post
        <?php } ?>
    	<!-- Stop The Loop (but note the "else:" - see next line). -->
    	<?php endwhile; else: ?>
     	<!-- The very first "if" tested to see if there were any Posts to -->
     	<!-- display.  This "else" part tells what do if there weren't any. -->
     	<p>Sorry, no posts matched your criteria.</p>
    	<!-- REALLY stop The Loop. -->
    	<?php endif; ?>
                // create the navigation above the content
                // calling the widget area 'single-top'
                // calling the widget area 'single-insert'
                // create the navigation below the content
                // calling the comments template
                // calling the widget area 'single-bottom'
    		</div><!-- #content -->
    	</div><!-- #container -->
        // action hook for placing content below #container
        // calling the standard sidebar
        // calling footer.php
    Posted 5 years ago #
  2. AnotherAndrew

  3. AnotherAndrew

    OK, now I need some help. On my single page I have this at the top:

    $post = $wp_query->post;
    if ( in_category('10') ) {include(TEMPLATEPATH . '/single-10.php');}
    else {include(TEMPLATEPATH . '/single.php');

    But it doesn't display several of my functions unless I have this:

    $post = $wp_query->post;
    if ( in_category('10') ) {include(TEMPLATEPATH . '/single-10.php');}

    But if I use this I end up with an extra post after the ending html tag.

    I am confused. Does anyone know how to remedy? Can I not write a function that achieves the same? And have all of my other functions display? Is there a better way to do this?

    Posted 4 years ago #
  4. AnotherAndrew

    Answering my own question.

    Include the coe below in functions.php and it will automatically generate a template if you already have one set up. In my case I have already set single-10.php as a template.

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    Posted 4 years ago #
  5. i would also suggest the Custom Post Template plugin. provides the same functionality as page templates, only for posts:

    Posted 4 years ago #
  6. AnotherAndrew

    HELP! Something is amiss.

    My custom post page is not being used, entirely. I can't get any of my functions to be used in the template file. Also, I can delete thematic function calls and yet they are still being used.

    Is this a problem with the thematic theme?

    Anyone have any experience or tips?

    Posted 4 years ago #
  7. AnotherAndrew

    Custom post templates don't seem to work with thematic.

    Therefore custom post templates must be placed in the parent theme, in this case, must be placed in the thematic theme folder.

    Defeats the purpose of parent and child themes, but problem solved!

    Posted 4 years ago #
  8. you sure? i'm pretty sure that i've used them in my child themes. and i just posted in SoupKing's thread that this

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    could be failing b/c TEMPLATEPATH is pointing to the Thematic folder while STYLESHEETPATH would point to your child folder

    Posted 4 years ago #
  9. AnotherAndrew

    Helgatheviking, sorry for the cross posting.

    You are right it needs to have STYLESHEETPATH to work with child themes.

    // create single.php template files for categories based on id, EX single-10.php
    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(STYLESHEETPATH . "/single-{$cat->term_id}.php") ) return STYLESHEETPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.