• Hi all,
    I´m currently working on an update for one of my themes and I want to add a functionality to the themes options page to edit a tabbed interface.

    Basically it works perfect. You can define a tab title and a tab content. The tab content works fine as lon as you use regular text and even HTML formating. But I want to enable also PHP for example to put a list of recent posts inside such a tab.

    The output of the option in the theme works basically like this:

    echo prinz_get_option(‘prinz_tab2_content’);

    But this “kills” the PHP tags. The sourcecode looks like that:

    <div style=”” class=”ui-tabs-panel” id=”fragment-2″>
    <h3 class=”title”>Recent Posts</h3>
    <p>To show the recent posts is just one thing you can use this tabbed section
    for. There are many more. It´s up to your creativity.</p>

      <!–?php wp_get_archives(‘type=postbypost&limit=7’); ?–>

    <!– END TAB 2 –>
    </div>

    You can see the PHP tags are placed in HTML comments and I have no clue why.

    Does anyone have an idea how to get PHP code working here?

    Thanks in advance
    Michael

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter michael.oeser

    (@michaeloeser-1)

    Sorry but I was not talking about seperating themes options into tabs.

    I mean I want to add content on a themes options page that generates content for a tabbed area on the frontend. This content can be text, HTML code (both works fine), javascript or PHP code (which does not -> see my code example above)

    The “only” problem I have is that PHP code entered on the options page gets stripped out or destroyed on the frontend.

    Why enter PHP into the theme options array? Why not output the appropriate PHP on the front end based on a the value of a given option?

    It doesn’t need to get striped out or destroyed. It simply isn’t executed. It is outputted in the HTML document after the PHP compiler is terminated.

    You won’t be able to get that piece of code executed like that. You’ll need to use either a function like exec() or eval(), both of which are banned by the WordPress theme directory, or to use create_function() and place the code inside the function.

    But as esmi said, it it way more efficient to hard code the PHP and execute it based on a retrieved option. This way you don’t get unexpected behaviour and you are sure nobody can insert evil code in there.

    Thread Starter michael.oeser

    (@michaeloeser-1)

    The reason why I want to do that is that I want to give the user a functionality to build their own tabbed section. As I mentioned this works great for HTML and regular text. Would have been nice to be able to also use WordPress template tags e.g to output the most recent articles etc. But obviously this doesn´t work.

    Well then I need to find another solution with partly hardcoded stuff that can be switched on and off. Not as flexible as I wanted it to have but it will work anyway.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using PHP Code in a themes options page’ is closed to new replies.