WordPress.org

Ready to get started?Download WordPress

Forums

Collapse-O-Matic
[resolved] putting the shortcode into my template (12 posts)

  1. traypup
    Member
    Posted 6 months ago #

    Hi there,
    I've tried a few different ways and I'm close, but my syntax, I think, is throwing things off. Can someone help me get my code right?

    I put together a FAQ page using Advanced Custom Fields. That bit is working great. Now I want to add in C-o-M so the user can click the titles and show the answers.

    I had this:

    [expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]')

    and it showed the question titles and answers, but also the brackets and "expand" code, so I realized I needed to call the shortcode first and did this:

    <?php echo do_shortcode('[expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]') ?>

    And the page is showing the error
    Parse error: syntax error, unexpected T_STRING

    Any suggestions on how to fix?
    Thank you!

    http://wordpress.org/plugins/jquery-collapse-o-matic/

  2. Baden
    Member
    Plugin Author

    Posted 6 months ago #

    you almost have it. Try:

    <?php echo do_shortcode('[expand title="'.the_sub_field('question_title').'"]'.the_sub_field('question_answer').'[/expand]'); ?>

    Please let us know if this works for you.

  3. traypup
    Member
    Posted 6 months ago #

    Ok, cool, the error message isn't coming up any more, but I'm still not getting the collapsing functionality. All of the Qs and As are just laid out on the page. But the arrows are clickable and change back and forth between pointing up and down! :)

  4. Baden
    Member
    Plugin Author

    Posted 6 months ago #

    under the plugin option page (Dashboard > Settings > Collapse-O-Matic) check and make sure that the check box for "Shortcode Loads Scripts" is UNchecked.

    For further assistance you will need to share a link so we can trouble shoot further.

  5. traypup
    Member
    Posted 6 months ago #

    It is unchecked.

    Can I email you a link and login? I have the site hidden at the moment since it's in development. Thank you!

  6. Baden
    Member
    Plugin Author

    Posted 6 months ago #

    yes. just be sure to include a link to this thread and shoot it to us info [at] twinpictures [dot] de

  7. traypup
    Member
    Posted 6 months ago #

    thank you! emails will come from websmith [at] eeep [dot] com

  8. Baden
    Member
    Plugin Author

    Posted 6 months ago #

    We took a look, and the_sub_field('question_answer') is returning NULL.

    var_dump(the_sub_field('question_answer'));

    Please verify that the_sub_field('question_answer') is the correct way to call the faq answer.

  9. traypup
    Member
    Posted 6 months ago #

    Interesting. That is the correct field name. I took a screen shot of the ACF page that shows the fieldnames: https://www.evernote.com/shard/s30/sh/9016444c-eaf8-44dc-80e9-a8058c0f2491/1ad47ac4cd63bf1438ececb6d026bb49

    If you look at the FAQ page (http://eeep.com/crl/faq-for-physicians/), you'll see that the contents of that field show up in the page...so I'm not sure how it returns NULL. (Unless I'm not understanding what you're saying!)

  10. traypup
    Member
    Posted 5 months ago #

    Do you have any other ideas on this issue?

  11. traypup
    Member
    Posted 5 months ago #

    It's fixed. I prevailed upon a colleague to take a look. Here's what he did:

    Just made a couple of simple changes. You just needed to change "the_sub_field" to "get_sub_field". The "the_" call will display the information whereas "get_" stores a value which works with the plugin because it's creating a link from the title.

    I've left the title as the_field - however, if you change this to "get_sub_field" it will create the title as a link and move the arrow to the left of the title. It's up to you I don't think it effects usability at all.

    I simply deleted

    <?php

    //var_dump(the_sub_field('question_answer')); //returns null

    echo do_shortcode('[expand title="'.the_sub_field('question_title').'"]'.the_sub_field('question_answer').'[/expand]');

    ?>

    and replaced it with

    <?php

    //var_dump(the_sub_field('question_answer')); //returns null
    $title = the_sub_field('question_title');
    $answer = get_sub_field('question_answer');

    echo do_shortcode('[expand title="' . $title . '"]' . $answer . '[/expand]');

    ?>

  12. Baden
    Member
    Plugin Author

    Posted 4 months ago #

    glad you got it working

Reply

You must log in to post.

About this Plugin

About this Topic