Keryn Gill Keryn Gill - 5 months ago 10
PHP Question

Trying to create a second loop-single.php to display different posts


  • Basic wordpress install, using a child theme.

  • Have a regular "blog", and also a "portfolio" post type

  • 2 loop files loop-single.php for blog, and loop-portfolio.php for portfolio

  • My portfolio page always shows up as if there is no styling: http://www.longevitygraphics.com/new/portfolio/dog-patch/

  • Both "loops" are identical in code (except I removed the "next" and "previous" links in portfolio). So I can tell it's picking up the file as I don't see the next/prev navigation, but I'm not sure why there is seemingly no style to the page.



I have tried the following three things unsuccessfully:




if(is_post_type_archive('portfolio')){
include(TEMPLATEPATH . '/loop-portfolio.php');
}else{
include(TEMPLATEPATH . '/loop-single.php');
}





if(is_post_type_archive('portfolio')){
include(STYLESHEETPATH . '/loop-portfolio.php');
}else{
include(STYLESHEETPATH . '/loop-single.php');
}





if(is_post_type_archive('portfolio')){
include(get_stylesheet_directory_uri() . '/loop-portfolio.php');
}else{
include(get_stylesheet_directory_uri() . '/loop-single.php');
}





To clarify, this is my entire loop... I am not missing calls to
get_header()
, or
get_footer()
, but for some reason it's not picking them up:

<?php get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php
if(is_post_type_archive('portfolio')){
include(TEMPLATEPATH . '/loop-portfolio.php');
}else{
include(TEMPLATEPATH . '/loop-single.php');
}
?>
</div><!-- #content -->
</div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Answer

So instead of trying to direct the script to my loops in single.php, I ended up just making a separate single.php file for my portfolio custom post type.

Final Result

  • single.php
  • single-portfolio.php
  • loop-single.php
  • loop-portfolio.php

single.php

<?php get_header(); ?>

    <div id="container">
        <div id="content" role="main">

        <?php get_template_part( 'loop', 'single' ); ?>

        </div><!-- #content -->
    </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

single-portfolio.php

<?php get_header(); ?>

    <div id="container">
        <div id="content" role="main">

        <?php get_template_part( 'loop', 'portfolio' ); ?>

        </div><!-- #content -->
    </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>