WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problem with combining two php codes (6 posts)

  1. SaLiXeM
    Member
    Posted 9 months ago #

    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?

  2. Chris
    Member
    Posted 9 months ago #

    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' );
    }
    ?>
  3. SaLiXeM
    Member
    Posted 9 months ago #

    Yes it works!
    Really thanks mate.

  4. SaLiXeM
    Member
    Posted 9 months ago #

    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?

  5. Chris
    Member
    Posted 9 months ago #

    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

  6. SaLiXeM
    Member
    Posted 9 months ago #

    Thank you Chris :)

Reply

You must log in to post.

About this Topic