• Resolved morfe1

    (@morfe1)


    Hi there,

    I’m trying to create a custom Visual Composer element based on your plugin. I’m using roll-your-own way because I didn’t find a proper way to pass the variables in the shortcode, being put into the php code of template.

    I don’t know if there is a way to dynamically assign unique id to each element, but at the moment same ids on multiple divs cause them to behave like this.
    https://pdidner.staging.wpengine.com/14628-2/

    The first one is collapsed by default, but any other element is expanded and if you click on any of them – the first will expand and the other 3 will collapse, as if they were in a group.

    Maybe you can help me to find a proper way to keep them all separated and collapsed by default.

    <div id="test_event" class="collapseomatic">
               	<h3 class="vc-event-title">' . $title . '</h3>
    			<p><strong>' . $location . '</strong></p>
    		</div>
    		<div id="target-test_event" class="collapseomatic_content">' . $content2 .'<br>
    			<a href="' . $link . '">Read More</a>
    		</div>
    

    another possibility would be something like

    echo do_shortcode( '[expand title="Sith" trigclass="noarrow"]Target Content[/expand]' );

    But I have 2 issues there:
    it breaks php for some reason
    Parse error: syntax error, unexpected 'title' (T_STRING), expecting ']'
    I’m not sure how to properly pass the above variables in the shortcode

    Thank you in advance

    • This topic was modified 7 years, 3 months ago by morfe1.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author twinpictures

    (@twinpictures)

    Lots going on here.

    First, it looks like you are looping through events of some sort. These events should have a unique ID associated with them, no?

    The do_shortcode function should work, maybe try swapping the quotes and double quotes?

    Please provide more info on how you are looping through your events/elements

    Thread Starter morfe1

    (@morfe1)

    I have created a custom element, which saves 4 variables: title, date,content and link.
    And then it passes them to the html code with the collapseomatic example I pasted first.

    The full code of the element can be found here https://pastebin.com/XZZiExbz

    These events should have a unique ID associated with them, no?

    Normally yes, and if I add unique ids manually everything works fine.

    The case is that my boss doesn’t want to mess with the source html code and set ids all the time. So I was looking to simplify it to 4 text fields. But I didn’t find how to assign unique IDs to each element’s div containers automatically and currently they use the same ids (it doesn’t work if I try without ids).

    So I asked you if you know the way to use it without unique ids. Or about the way to assign unique ids for each element.

    The simple shortcode like ‘[expand title=”Sith” trigclass=”noarrow”]Target Content[/expand]’ sets them automatically. But I can’t get it to work. Tried swapping the quotes and escaping them but all I get is errors or commented php code.

    Plugin Author twinpictures

    (@twinpictures)

    This is a bit beyond the support we can provide over the forum.
    If you are intrested, please contact us direct at info [at] twinpictures [dot] de and include a link to this thread. We will work with you direct to find a solution.

    Thread Starter morfe1

    (@morfe1)

    Nevermind, I’ve found a way to do it with jquery
    FYI:

    jQuery(‘div[id=test_event]’).each(function(i,el){
    el.id=el.id+’-‘+i;
    });

    jQuery(‘div[id=target-test_event]’).each(function(i,el){
    el.id=el.id+’-‘+i;
    });

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Roll-your-own and custom VC element’ is closed to new replies.