Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a breadcrumb code that will not place a link on two custom single post pages linking back to two custom post type index pages. The full Breadcrumb code can be seen here: http://pastebin.com/xNwXxWv6


if(get_post_type() == 'Portfolio'){
 echo '<a href="' . 'http://www.mysite.com/web-portfolio'  . '">' .  'Portfolio'. '</a>' . $markup;

} else if(get_post_type() == 'Artwork'){
 echo '<a href="' . 'http://www.mysite.com/art-portfolio'  . '">' . 'Artwork' .  '</a>' . $markup;
}


EDIT: This has been resolved with the code above, thanks all who helped.

share|improve this question
    
if( !$type == 'portfolio') is confusing. Do you mean if( $type != 'portfolio')? If that's the case, it will help those who answer get a better grip on your logic. !$type looks like a mistake to me at first glance. –  Brian Fegter Aug 24 '12 at 19:53
    
What do you mean by linking to a "single.php template"? You don't link to template files, but rather to posts. WordPress determines the appropriate template file to use to render the current query. Also: please post the rendered output of that code, and explain what you expected that output to be. –  Chip Bennett Aug 24 '12 at 20:52
    
Let me try to rephrase my question: what link are you trying to display there? I assume you're trying to display a link either to a single post of a custom post type, or else the archive index page for that custom post type? –  Chip Bennett Aug 25 '12 at 1:36
    
Also, looking at your pastebin: it looks like you're missing a closing brace on lines 66-68, to correspond to the if statement opening brace on line 63. If so, this question is simply a PHP syntax error, and not WordPress-related. –  Chip Bennett Aug 25 '12 at 1:41
    
if( $type != 'Portfolio') { Why != and not == ? –  Tom J Nowell Aug 26 '12 at 13:20

2 Answers 2

up vote 1 down vote accepted

If you read the codex you will see that is_single accepts post id's / titles / slugs and

EDIT
If you are using two custom post types then WP will select the right single-POSTNAME.php And in your check you best check the posttype like:

if ( get_post_type() == 'postfolio' ) { /*do stuff*/ }
share|improve this answer
    
I failed to see it does not except templates. I've been reading the codex for a year but it's logic often fails me. Even using the slug, id, or title produces no effect still shows one or the other. Help? –  zoaCode Aug 24 '12 at 10:32
    
@Zoa See my update –  janw Aug 24 '12 at 10:54
    
The echo provided above seems correct, if you made changes to your code update your answer. –  janw Aug 24 '12 at 12:39
    
I've updated my code will you take a look? –  zoaCode Aug 24 '12 at 19:35
    
your { and } are all screwed up you should be getting PHP errors fix that first If you don't see errors turn on WP_DEBUG –  janw Aug 25 '12 at 6:44

Referring to the template heirarchy here:

http://codex.wordpress.org/Template_Hierarchy

enter image description here

We can see your choices out of the box are:

  • single.php
  • single-post.php
  • single-{post type}.php

But judging from your problem, I would recommend against using multiple templates.

Instead define via post meta/custom fields wether it is a portfolio or an art piece. You can add a checkbox or radio buttons in the backend to control this, or just manually set it.

$url = '<a href="">artwork url</a>';
$type = get_post_meta($post->ID,'zoa_post_type',true);
if($type == 'portfolio'){
    $url = '<a href="">portfolio url</a>';
}

Also, is_single doesn't take a template name.

Edit

It would appear you neglected to mention you are using 2 different custom post types.

In that case:

if(get_post_type() == 'Portfolio'){
    echo '<a href="' . 'http://www.mysite.com/web-portfolio'  . '">' . 'Portfolio' .  '</a>';
} else if(get_post_type() == 'Artwork'){
    echo '<a href="' . 'http://www.mysite.com/art-portfolio'  . '">' . 'Artwork' .  '</a>';
}
echo $markup;
share|improve this answer
    
Comments purged. This is not appropriate use of them, we have chat rooms (private if necessary) for that. –  Rarst Aug 28 '12 at 13:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.