WordPress.org

Ready to get started?Download WordPress

Forums

is_attachment not working ? (13 posts)

  1. Evita
    Member
    Posted 6 years ago #

    Has anybody here also problems with is_attachment in WP 2.5?
    I am making a breadcrumb navigation and want to call is_attachment blablabla ..., but I have no luck. It displays nothing.
    Any ideas?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    What exactly are you trying to do? I don't see how you'd use is_attachment in breadcrumbs...

  3. Evita
    Member
    Posted 6 years ago #

    I am trying to make a simple breadcrumb navigation like:
    home - category name - gallery name - image name

    It´s easy for normal posts like:
    home - category name - single post name

    but with attachments it doesn´t work. I have now
    home - category name (my gallery) - gallery name

    that´s fine but on the single image page (image.php) it shows:
    home - category name of default category (not my gallery category) - image name

    I tried is_attachment, is_attachmet || in_category, is_attachmet || is_category and is_single || is_attachment - nothing works.

    Hope you can understand my terrible English.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Okay, show me the code you're using to do this, or trying to use to do this. I'll understand the code much better. :)

  5. Ivovic
    Member
    Posted 6 years ago #

    I can imagine Otto's GF saying something like:

    if (!rubbish_out()) take_rubbish('out');

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Heh. I'm just saying that I still don't understand why he'd use is_attachment to do something like that. I also don't know where he's getting the category name and gallery name and so don't know what code to tell him to use.

  7. Evita
    Member
    Posted 6 years ago #

    Here is my code:

    <?php if ( is_home() ) { ?>
    &nbsp;&nbsp;<?php bloginfo('name'); ?> - Aktuell
    <?php } elseif ( is_category() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Rubrik <?php single_cat_title(); ?>
    <?php } elseif ( is_single() || in_category(6) ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Rubrik <?php foreach((get_the_category()) as $cat) {
    if ($cat->cat_ID != "2") {
    echo '<a href="' . get_category_link($cat->cat_ID) . '">' .
    $cat->cat_name . '</a> ';
    }
    }
    ?><?php wp_title(); ?>
    <?php } elseif ( is_tag() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Tag <?php single_tag_title(); ?>
    <?php } elseif ( is_page() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Seite <?php wp_title(''); ?>
    <?php } elseif ( is_404() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Error 404
    <?php } elseif ( is_search() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;"?php echo wp_specialchars($s); ?>
    <?php } elseif ( is_day() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Archiv <?php the_time('j. F Y'); ?>
    <?php } elseif ( is_month() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Archiv <?php the_time('F Y'); ?>
    <?php } elseif ( is_year() ) { ?>
    &nbsp;&nbsp;<a href="<?php bloginfo('url'); ?>">Home</a>&nbsp;&raquo;&nbsp;Archiv <?php the_time('Y'); ?>
    <?php } else { ?>
    
    <?php } ?>

    You can see it here, that´s my category gallery. Breadcrumb navigation is on the top.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I see what you're doing, but I don't see the call to is_attachment() in there...

    But, your problem seems to be that the attachments don't inherit the category of their parent. You want them to show the category of the gallery, correct?

    Note that an attachment post is also a single post. So is_single() will be true when is_attachment() is true. Therefore you'll need it above your check of is_single().

  9. Evita
    Member
    Posted 6 years ago #

    But I tried it with
    is_single || is_attachment and also with
    is_single || is_attachment || is category (my ID) and also with
    is_single || is_attachment || in category (my ID)
    and it did not work.

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    What, exactly, did not work? I still am not quite seeing what the problem is here.

    Attachment posts are not actually in your gallery category. They're just not. All attachments are really in the default category, whatever that may be. So if you're using that, then it is doing that get_the_category() thing, and will get the default category. That is correct behavior, because attachment posts are in the default category.

    If you want to display something different, then you need to do this:

    ...
    } elseif (is_attachment()) {
    echo "display something special for attachment here";
    } elseif (is_single() ...
  11. Evita
    Member
    Posted 6 years ago #

    } elseif (is_attachment()) {
    echo "display something special for attachment here";
    } elseif (is_single() ...

    That´s exactly what I´ve tried firstly and that´s exactly why I opend this thread - it does not work (for me).

  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Hmm... Well, that should work. Does the image.php template file get used when you view an attachment? If so, then is_attachment() absolutely works, because that's how it knows to look for an attachment template.

  13. Evita
    Member
    Posted 6 years ago #

    Does the image.php template file get used when you view an attachment?

    Yes.

Topic Closed

This topic has been closed to new replies.

About this Topic