WordPress.org

Ready to get started?Download WordPress

Forums

List Related Attachments
[resolved] Shortcode not working in archive view (7 posts)

  1. tlkativ
    Member
    Posted 1 year ago #

    I also posted this in the Simple Hooks forum as I am not quite sure which plug-in is causing the problem.

    I am trying to display a shortcode for the List Related Attachments plug-in in the post-meta area using Genesis Simple Hooks but whenever I check both "Execute Shortcodes on this hook?" and "Execute PHP on this hook?" the shortcode disappears. The shortcode works without the PHP but then the attachment doesn't display on the category archive. Am I not allowed to use this shortcode in a template?

    Here is my code:
    \\
    <?php if (is_archive('rides')) { ?>
    [list-related-attach]
    <?php } ?>
    \\

    http://wordpress.org/extend/plugins/list-related-attachments-widget/

  2. Baden
    Member
    Plugin Author

    Posted 1 year ago #

    in php, you will want to use do_shortcode

  3. tlkativ
    Member
    Posted 1 year ago #

    Baden, thanks for the suggestion. I also tried that but the shortcode doesn't work with just the "Execute PHP on the hook?" checked. Nothing shows up. Am I missing something in my code?

    <?php if (is_archive('rides')) {
    echo do_shortcode('[list-related-attach]');
    } ?>

  4. Baden
    Member
    Plugin Author

    Posted 1 year ago #

    Tlkativ,

    You might want to brush up on your is_archive function:

    is_archive() does not accept any parameters. If you want to check if this is the archive of a custom post type, use is_post_type_archive( $post_type )

    So... what is 'rides' exactly? Is it a post type? A page slug?

    Step 1: get this to work:

    if (is_archive()) {
         echo 'Hey Dude';
    }

    Step 2. Once the above works, then just echo the do_shortcode as you posted above:

    if (is_archive()) {
         echo do_shortcode('[list-related-attach]');
    }

    Hope this helps get you squared away.

  5. tlkativ
    Member
    Posted 1 year ago #

    Baden,

    Thanks again. The 'Hey Dude' showed up perfectly (as expected), but as soon as I swapped in the shortcode, the code disappeared. 'Rides' is a custom post type but I am trying to get the attachments to show on a category archive page as you guessed. The post_type_archive call gave me the same results.

    It seems like the Simple Hooks doesn't recognize both php and shortcodes in the same field area. Is there something I can add to my functions.php file to help this along?

  6. Baden
    Member
    Plugin Author

    Posted 1 year ago #

    Sounds like an issue with Simple Hooks not dealing with do_shortcode. OK, then try this:

    <?php
    if (is_archive()) {
    ?>
         [list-related-attach]
    <?php
    }
    ?>
  7. tlkativ
    Member
    Posted 1 year ago #

    Baden,

    That code above was what I started with and it didn't work. However, after exploring the issue a little more, I noticed that the shortcode was working on certain archive pages and not on others. So, if I find out why that is I will post an update here. Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic