WordPress.org

Ready to get started?Download WordPress

Forums

Global Content Blocks
[resolved] JS and PHP in one block (8 posts)

  1. thatwastaxing
    Member
    Posted 3 years ago #

    Hi,

    Thanks for the plugin!

    I've gt a JS that I need to run at the end of a post that contains a line of PHP in it:

    <script type="text/javascript">
    var mytabs=new ddtabcontent("post-<?php the_ID(); ?>") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs' state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>

    However, the PHP code doesn't run. If I paste the code directly at the end of the post and run it with Exec-PHP plugin, it works fine.

    Any ideas?

    http://wordpress.org/extend/plugins/global-content-blocks/

  2. benz1
    Member
    Plugin Author

    Posted 3 years ago #

    Looking into this, will come back to you if and when I have a solution.

  3. benz1
    Member
    Plugin Author

    Posted 3 years ago #

    Basically the php block is not designed to work with mixed content. It simply evaluates the entire content of the block as php (which is why we say to exclude the <?php ?> tags). If the block contains non-php then this is simply added to the content as it is - the JS will be executed as it's client side but the php will not.

    We may look at adding another block type that processes the <?php ?> in a future release. In the meantime if you are using Exec-PHP, try just adding your code as as a standard block type, e.g., anything other than a PHP block and see if Exec-PHP can handle it. Otherwise all I can suggest if that you create 3 blocks and add them one after the other:

    Non-PHP Block

    <script type="text/javascript">
    var mytabs=new ddtabcontent("post-

    PHP Block
    the_ID();

    Non-PHP Block

    ") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs' state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>

    and see if that works?

    Would be interested to know if either of these solutions work?

  4. thatwastaxing
    Member
    Posted 3 years ago #

    Hi,

    I'd already tried the first solution and it didn't work.

    Dividing the code up into 3 blocks and putting the shortcodes on separate lines in the post produced this:

    <script type="text/javascript">
    var mytabs=new ddtabcontent("post-<br />
    82<br />
    ") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs' state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>

    Dividing up the code and putting the shortcodes on one line in the post produced:

    <script type="text/javascript">
    var mytabs=new ddtabcontent("post-[contentblock id=5]") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs' state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>

    For now, I'll just paste this particular code directly into each post and look out for an update to your plugin in the future. Thanks!

  5. benz1
    Member
    Plugin Author

    Posted 3 years ago #

    Try running the following as a PHP Block:

    echo '<script type="text/javascript">
    var mytabs=new ddtabcontent("post-'.the_ID().'") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>';
  6. thatwastaxing
    Member
    Posted 3 years ago #

    I get:

    82<script type="text/javascript">
    var mytabs=new ddtabcontent("post-") //enter ID of Tab Container
    mytabs.setpersist(true) //toogle persistence of the tabs state
    mytabs.setselectedClassTarget("link") //"link" or "linkparent"
    mytabs.init()
    </script>
  7. benz1
    Member
    Plugin Author

    Posted 3 years ago #

    Sorry, looks like mixed type blocks won't work in this version.

  8. thatwastaxing
    Member
    Posted 3 years ago #

    Thanks for looking into it anyway!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic