WordPress.org

Forums

Custom Content by Country (by iControlWP)
[resolved] do_shotcode issue using get_template_part (6 posts)

  1. elundin
    Member
    Posted 2 years ago #

    Hi!

    First of all! Thanks for a fantastic plugin. I have used for a lot of static content and worked brilliant.

    This time I'm working on a site that dispplays cd-releases. Some of them will be available do everyone but some will be restricted to specific countries only.

    I'm using the do_shortcode function as explained in the wordpress codex:

    echo do_shortcode('[iscorrect]'.$text_to_be_wrapped_in_shortcode.'[/iscorrect]');

    But instead of just showing text I want to use the same template part that I'm using for all the releases. Like this:

    if ( get_field('releaseCountry') == 'Japan' ) { $text_to_be_wrapped_in_shortcode = get_template_part( 'content', 'release' );
    echo do_shortcode('[CBC country="jp, ch" show="y"]'.$text_to_be_wrapped_in_shortcode.'[/CBC]');
    } else {
    get_template_part( 'content', 'release' );
    }

    But when I'm using the get_templet_part in between the shortcode it shows the content anyway.

    Am I doing anything wrong?

    Cheers

    //Emil

    http://wordpress.org/plugins/custom-content-by-country/

  2. Paul G.
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Emil,

    I believe because this function, get_template_part(), will print out the contents of the template you've loaded whenever you call it... and you call it in both instances.

    I don't have an API access to getting the country code, but I'm planning to add that to a future release. That would make what you're trying to achieve easier. Until then you could try:

    ob_start();
    get_template_part( 'content', 'release' );
    $text_to_be_wrapped_in_shortcode = ob_get_contents ();
    ob_end_clean();
    
    if ( get_field('releaseCountry') == 'Japan' ) {
    	echo do_shortcode('[CBC country="jp, ch" show="y"]'.$text_to_be_wrapped_in_shortcode.'[/CBC]');
    } else {
    	echo $text_to_be_wrapped_in_shortcode;
    }
  3. elundin
    Member
    Posted 1 year ago #

    Thanks Paul, worked great!

    Thank you for taking the time to help me and for a fantastic plugin. Keep up the good work!

    //Emil

  4. Paul G.
    Member
    Plugin Author

    Posted 1 year ago #

    No problem at all... glad it worked for you! :)

    Would you be interested in leaving a review for the plugin? ;)

    Cheers,
    Paul.

  5. tech17
    Member
    Posted 1 year ago #

    Hello Paul

    Greetings For the day!!

    I m using our plugin it is working very well in the pages, but i m facing an issue to write a short code in the .php file

    The thing is i want to show different contact number to there respective countries,

    Can you please help me to write php short code for that.

    You can see the contact number i want to change as per country

    at the top http://www.technoweber.com/

    Thank You Very much for such a wonderful plugin

  6. Paul G.
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Shortcodes cannot be used outside of posts, so the shortcodes for this plugin wont work.

    However, if you have enabled the option in the plugin for developer mode, the plugin wont set cookies that reference the country code. It looks like on this link you sent that those cookies are not currently being set, so may be you have developer mode on.

    What you can do is, check for those cookies when the pages load using PHP and change the phone number based on the country code. In this way you can display content you want to different countries. -but you'll need the cookie data.

    The cookie names for the country code is:
    cbc_country_code
    cbc_country_name

    hope that helps.
    Paul.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Content by Country (by iControlWP)
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic