New Landing How can we help? Themeforest Theme Support Dante Shortcode with variables?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Posted in: Dante
  • #154045
    Dr.Peril
    Member
    Post count: 10

    Hey all,

    Quick question. I’m trying to print a shortcode and it’s behaving oddly.

    My code:

    <?php $ba_score = the_field('beer_advocate_score'); echo do_shortcode('[chart percentage="'.$ba_score.'" size="170" barcolour="" trackcolour="" content="'.$ba_score.' / 100" align="center"]'); ?>
    

    The $ba_score is just a numerical value, 84 for example.

    What I get when the function runs can be seen in the screenshot.
    Basically, it breaks the short code and prints the values first occurrence and skips the second entirely.

    Thoughts?

    (I’m ok, printing the variables into the html the shortcode generates but the animation seems to break when I do that).

    Thanks!

    Attachments:
    You must be logged in to view attached files.
    #154188
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Where are you inserting this code?
    Thanks
    Mohammad

    #154451
    Dr.Peril
    Member
    Post count: 10
    This reply has been marked as private.
    #154457
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Try this format instead.

    
    <?php 
      $ba_score = the_field('beer_advocate_score');
      $ba_score += '/ 100';
      echo do_shortcode('[chart percentage="'.$ba_score.'" size="170" barcolour="" trackcolour="" content="'.$ba_score.'" align="center"]'); 
    
    ?>

    -Rui

    #154509
    Dr.Peril
    Member
    Post count: 10

    I’ve implemented the code you provided and it seems to be a solid step in the right direction, however I’m still getting raw data output and no animation. I’ve left the code in the page so you can see the output.

    Thanks!

    #154568
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Your data percentage is zero. So animation is not working. Your $ba_score have zero value.
    Thanks
    Mohammad

    #157231
    Dr.Peril
    Member
    Post count: 10

    Hey Mohammad,

    I’ve double checked the code, and the value is being output above the circle. You can see little numbers. These are the printed output of the first time the variable is called (in the shortcode) the second time it’s called (what would be the printed text inside the circle) is coming back blank, so 0.

    It’s like the code is printing the variable value outside of the theme’s shortcode then failing…

    thanks!

    #157235
    Dr.Peril
    Member
    Post count: 10

    This code enables both the circle label animation and the text in the circle to work:

    
    								<?php
    									$ba_score = 42;
    								  // $ba_score = the_field('beer_advocate_score');
    								  echo "Test".$ba_score;
    								  //$ba_score += '/ 100';
    								  echo do_shortcode('[chart percentage="'.$ba_score.'" size="170" barcolour="" trackcolour="" content="'.$ba_score.' / 100" align="center"]');
    								?>

    I’m investigating the the_field(”) function from Advanced Custom Fields.

    Thoughts?

    #157240
    Dr.Peril
    Member
    Post count: 10

    Looks like I just needed to take a step back.

    From Advanced Custom Fields Documentation:

    the_field()
    Displays the value of the specified field. (this is the same as “echo get_field($field_name)”)

    get_field()
    Returns the value of the specified field.

    This is a very versatile function. You can use it to store a value, echo a value and interact with a value. Please note the type of variable returned is relative to the field type. Eg: A repeater will return a multidimensional array.

    So the code:

    <?php
    									//$ba_score = 42;
    								  $ba_score = get_field('beer_advocate_score');
    								  echo "Test".$ba_score;
    								  //$ba_score += '/ 100';
    								  echo do_shortcode('[chart percentage="'.$ba_score.'" size="170" barcolour="" trackcolour="" content="'.$ba_score.' / 100" align="center"]');
    								?>

    Works.

    Thanks!

    #157252
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    you probably have to use the other function that also get’s the post id.

    the_field()

    something like the line below where 37 is the id of the post where you saved that specific custom field beer_advocate_score.

    
     $ba_score = the_field('beer_advocate_score', 37);
    

    -Rui

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register