Support » Plugins » Hacks » Problem with combining two php codes

  • Resolved SaLiXeM

    (@salixem)


    Hello,
    I have installed a plugin that can show a box with a message inside using a php code in theme.Here is the code that shows the box:

    <?php if(function_exists('stbHighlightText')) stbHighlightText('Test of function.', 'warning'); ?>

    I want to place the category description instead of “Test of function” using this code:

    <?php echo category_description( $category_id ); ?>

    I had tried to place the whole php code for category description into the first php code like this but it didn’t work.

    <?php if(function_exists('stbHighlightText')) stbHighlightText('<?php echo category_description( $category_id ); ?>', 'warning'); ?>

    Whats the problem?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You’re a) nesting PHP inside PHP (only one open tag is allowed) and b) you’re wrapping the code inside quotation marks so it will be handled as a plain text string.

    Try this instread:

    <?php
    if( function_exists( 'stbHighlightText' ) ) {
      stbHighlightText( category_description( $category_id ), 'warning' );
    }
    ?>

    Yes it works!
    Really thanks mate.

    Now I want to show it only if user is viewing category page, and not in every archive like tags etc.
    Can anyone help me?

    Maybe like this

    <?php
    if( function_exists( 'stbHighlightText' ) && is_category() ) {
      stbHighlightText( category_description( $category_id ), 'warning' );
    }
    ?>

    You can also show this only for specific categories or a bunch of categories: http://codex.wordpress.org/Function_Reference/is_category

    Thank you Chris 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem with combining two php codes’ is closed to new replies.