Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress single.php

Featured Replies

Oh boy I can't believe how complicated Wordpress makes this stuff :rolleyes:

 

Anyway I am following the instructions here to get round Wordpress wanting all my single posts to have the same template. :mellow:

 

I have added two new files to my theme templates = single1.php and single3.php - these are exact copies of the original single.php so there should be no problem with these files. Then I have edited single.php as per instructions but changing TEMPLATEPATH to STYLESHEETPATH because I am using a child theme. So my single.php now looks like this...

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include(STYLESHEETPATH . '/single3.php');
} else {
include(STYLESHEETPATH . '/single1.php');
}
?> 

 

Can anyone please tell me if this code looks ok because when I click any of my single posts I get a blank screen. :(

 

thank you

change stylesheet in the path to either of the below

 

<?php include bloginfo('template_directory'); ?>/filename.php

 

<?php include( TEMPLATEPATH . '/filename.php' ); ?>

 

Add the folder name before the file name, if the file is in a folder e.g.

 

<?php include( TEMPLATEPATH . '/header2.php' ); ?>/folder/filename.php

  • Author

change stylesheet in the path to either of the below

 

Thanks for suggestions but single.php [edit]=

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
<?php include bloginfo('template_directory'); ?>/single3.php
} else {
<?php include bloginfo('template_directory'); ?>/single1.php
}
?>

 

= white screen

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include(TEMPLATEPATH . '/single3.php');
} else {
include(TEMPLATEPATH . '/single1.php');
}
?>

 

= white screen.

 

And single1.php / single3.php are not in a folder.

 

Anyway I think i found a way round with a Single Post Template plugin.

 

thanks

Edited by Juc1

Thanks for suggestions but sidebar.php =

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
<?php include bloginfo('template_directory'); ?>/single3.php
} else {
<?php include bloginfo('template_directory'); ?>/single1.php
}
?>

 

= white screen

 

thanks

 

remove the php tags e.g. change to

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include bloginfo('template_directory'); ?>/single3.php
} else {
include bloginfo('template_directory'); ?>/single1.php
}
?>

  • Author

remove the php tags e.g. change to

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include bloginfo('template_directory'); ?>/single3.php
} else {
include bloginfo('template_directory'); ?>/single1.php
}
?>

 

 

 

 

single.php =

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include bloginfo('template_directory'); ?>/single3.php
} else {
include bloginfo('template_directory'); ?>/single1.php
}
?>

 

 

=

 

Any single post gives a white page.

 

thanks

single.php =

 

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include bloginfo('template_directory'); ?>/single3.php
} else {
include bloginfo('template_directory'); ?>/single1.php
}
?>

 

 

=

 

Any single post gives a white page.

 

thanks

 

Must be something up with your other code then, as that should grab the single3.php file. Is the file in the root of the theme e.g.

 

wp-content

themes

theme-name

theme-file.php

 

Also try this instead of your query

 

 <?php query_posts('posts_per_page=2'); ?>

 

To edit it, just add anything from thispage

  • Author

Must be something up with your other code then, as that should grab the single3.php file. Is the file in the root of the theme e.g.

 

wp-content

themes

theme-name

theme-file.php

 

 

wp-content/themes/titan_pro/single1.php

wp-content/themes/titan_pro/single3.php

 

=

 

<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
	<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<div class="post-header">
			<div class="tags"><?php the_tags( '<span>Tags</span> <p>', ', ', '</p>'); ?></div>
			<h1><?php the_title(); ?></h1>
			<div class="author"><?php printf(__ ( 'by %s on', 'titan'), get_the_author()); ?> <?php the_time(__ ( 'F jS, Y', 'titan')); ?></div>
		</div><!--end post header-->
		<div class="entry clear">
			<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail( array(250,9999), array( 'class' => ' alignleft border' )); ?>
			<?php the_content(__( 'read more...', 'titan')); ?>
			<?php edit_post_link(__( 'Edit', 'titan')); ?>
			<?php wp_link_pages(); ?>
		</div><!--end entry-->
		<div class="meta clear">
			<p><?php _e( 'From', 'titan' ); ?> → <?php the_category( ', '); ?></p>
		</div><!--end meta-->
	</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
	<?php comments_template( '', true); ?>
<?php else : ?>


<?php get_sidebar(); ?>

<?php get_footer(); ?>

 

thanks

  • Author

update - I tried this on another install...

 

single.php =

<?php include (STYLESHEETPATH . '/sidebar2.php'); ?>

 

Click on single post = gives the sidebar as expected.

 

 

single.php =

<?php include (STYLESHEETPATH . '/single1.php'); ?>

 

Click on single post = white page.

 

This tells me there is something wrong with single1.php... :huh:

  • Author

Must be something up with your other code then

 

Yes you are correct. Thanks for your help and I apologise for wasting your time in telling you that single1.php was ok when it wasn't. :(

 

single1.php now working ok =

 

 

<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
	<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<div class="post-header">
			<div class="tags"><?php the_tags( '<span>Tags</span> <p>', ', ', '</p>'); ?></div>
			<h1><?php the_title(); ?></h1>
			<div class="author"><?php printf(__ ( 'by %s on', 'titan'), get_the_author()); ?> <?php the_time(__ ( 'F jS, Y', 'titan')); ?></div>
		</div><!--end post header-->
		<div class="entry clear">
			<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail( array(250,9999), array( 'class' => ' alignleft border' )); ?>
			<?php the_content(__( 'read more...', 'titan')); ?>
			<?php edit_post_link(__( 'Edit', 'titan')); ?>
			<?php wp_link_pages(); ?>
		</div><!--end entry-->
		<div class="meta clear">
			<p><?php _e( 'From', 'titan' ); ?> → <?php the_category( ', '); ?></p>
		</div><!--end meta-->
	</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
	<?php comments_template( '', true); ?>
<?php else : ?>
<?php endif; ?>
</div><!--end content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

 

 

 

The bad single1.php posted above was missing the lines...

 

 

<?php endif; ?>
</div><!--end content-->

Yes you are correct. Thanks for your help and I apologise for wasting your time in telling you that single1.php was ok when it wasn't. :(

 

single1.php now working ok =

 

 

<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
	<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<div class="post-header">
			<div class="tags"><?php the_tags( '<span>Tags</span> <p>', ', ', '</p>'); ?></div>
			<h1><?php the_title(); ?></h1>
			<div class="author"><?php printf(__ ( 'by %s on', 'titan'), get_the_author()); ?> <?php the_time(__ ( 'F jS, Y', 'titan')); ?></div>
		</div><!--end post header-->
		<div class="entry clear">
			<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail( array(250,9999), array( 'class' => ' alignleft border' )); ?>
			<?php the_content(__( 'read more...', 'titan')); ?>
			<?php edit_post_link(__( 'Edit', 'titan')); ?>
			<?php wp_link_pages(); ?>
		</div><!--end entry-->
		<div class="meta clear">
			<p><?php _e( 'From', 'titan' ); ?> → <?php the_category( ', '); ?></p>
		</div><!--end meta-->
	</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
	<?php comments_template( '', true); ?>
<?php else : ?>
<?php endif; ?>
</div><!--end content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

 

 

 

The bad single1.php posted above was missing the lines...

 

 

<?php endif; ?>
</div><!--end content-->

 

Glad you got it working, sometimes we need to test everything around the code before we can get it to finally work

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.