Wpml and Custom Widgets - php

In WPML some times custom widgets developed could not get translated.
Any string is translatable if the you copy paste the string then that string if searchable in WPML is translatable.
I have a website that has 4-5 Custom widgets + some hard coded part
For example there was a string in hard coded part-
Bet on your favorite sports online
I made it WPML compatible-
WPML version
N.B. Before posting the question here I have invested around 3-4 hours in understanding all the FAQ's at wpml.org site.
My problem-
I have various widgets, one such widgets has this portion-
<div class="signupoffers">
<div class="signupText"> <h2><?php echo $signup_text_title?></h2>
<p><?php echo $signup_text_content?></p><br>
</div>
<div class="signupbuttonDiv">
<div class="RegisterBlock">
<div class="block"><h2><?php echo $signup_btn_title?></h2>
<div>
<?php echo $signup_btn_content; ?>
</div>
</div>
</div>
<?php //nsu_signup_form();?>
</div>
</div>
Lets take an example this one-
I tried this http://screencast.com/t/3hJCPJgylXS
but the above one doesn't worked.
and various other versions, but no help so far.
Content here is coming dynamically from widget entry. May be I have some syntax issue. Does any one has encountered such situation before, Please guide me how to do that. Thanks!!

Let me ask the question in different way-
The string here is coming in a dynamic format-
<h2><?php echo $signup_btn_title?></h2>
How to convert it into wpml version so that wpml can read and search this string.
I tried this one, but it didn't worked-
<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>

<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>
this is definitely wrong
If any of similar approach, it should read similarly to this:
<?php _e( $seocontent_text_title, 'your_text_domain' ); ?>
You would probably also need to edit/create a wpml-config.xml file.
You could also try something along this lines:
(icl_translate function in strings)
<?php echo icl_translate(context, name, value); ?>">
I think this could help you to understand further:
https://wpml.org/forums/topic/transform-echo-to-php_e/
https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/
https://wpml.org/documentation/support/wpml-coding-api/

Related

Editing certain parts of page template in User mode

I have a web page I am working on in WP which needs some customization.
Firstly I have created a page template that will be used over and over again, only changing parts of the content. I am wondering about available options for me when enabling this fact, through the Admin panel in the HTML Editor(if possible)...
Hope my question is clear enough for you all.
Let me add some code to show what I am trying to accomplish.
<div id="header-style">
<?php get_header();?>
</div>
<div id="content">
<div id="about">
//This is what i want to be able to edit
</div>
<div id="features">
//This is what i want to be able to edit
</div>
</div>
Dino:
There are lots of ways you could do this. The main question I would ask you is, who is going to be adding/editing this content? If you're going to have a community of people adding content, the input needs to be stripped and sanitized (to avoid injecting tags or other harmful content). If its just going to be you, then here's the easiest/fastest solution:
Use custom fields. If you can't see them in the post/page edit screen, go to the little tab on the top right of the post-edit screen that says Screen Options (or something like that) and click "Custom Fields".
Once you can see the Custom Fields edit box, you can add as many fields as you want. These are stored as post meta data. You can use the <?php the_meta(); ?> function in the loop to display all of your custom fields.
You can access a specific field by using get_post_meta(). You pass in the postID and the key of the meta field:
<?php echo get_post_meta(get_the_ID(), 'my_key'); ?>
So, for your example, you would add in the post-edit screen:
about: Some text to go in the about section.
features: Some text to go in the features section.
Then, you would access these on your page like so:
<div id="header-style">
<?php get_header();?>
</div>
<div id="content">
<div id="about">
<?php echo get_post_meta(get_the_ID(), 'about'); ?>
</div>
<div id="features">
<?php echo get_post_meta(get_the_ID(), 'features'); ?>
</div>
</div>

How to force a wordpress template to parse code instead of plain-text

I have recently installed a new template(more specifically SquirrelTheme - a free template) in my wordpress blog. It happens that I would like to have two buttons on my front page. Let's say button X and button Y. For creating these buttons I use a plugin called "MaxButtons" which allows you to easily create and manage a button and it's functions. After creating the said button, it gives you a shortcode that you can insert in your posts and pages - lets say [maxbutton id="1"] - to display it.
Unfortunately, after editing the template to my liking(removing divs I didn't intend to display), I can't seem to display these two buttons as the template parses plain-text, unlike the pages/posts apparently.
In case you are wondering how I am inserting the shortcode for the buttons, the template can be easily modified through the dashboard, in which I inserted the following in the field that dictates what is displayed on the specific part of my homepage:
[maxbutton id="1"] [maxbutton id="2"]
Like I said before, instead of showing the buttons as intended, I just see exactly what I type in the box.
I believe this is caused by how the template parses the text, as it uses its own function(? - php _e('...')) to echo the text:
<div class="full_content">
<center>
<?php if (squirrel_get_option('squirrel_slidehead') != '') { ?>
<h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1>
<?php } else { ?>
<h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1>
<?php } ?>
<?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?>
<h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>
<?php } else { ?>
<p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p>
<p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p>
<?php } ?>
</center>
</div>
My question is, how can I get it to display the buttons or any other code.
Thanks in advance.
You can call the function do_shortcode() to do the proper shortcode processing on some text.
Example:
echo do_shortcode('This is a button: [maxbutton id="1"]');

Get post by its ID (WordPress)

How do I get a Custom Post by its ID in wordpress and show its thumbnail, title and content? Here is what I am using, but didnt the content is messed up.
<div class="left-cont1">
<div class="left-cont1-text">
<?php
query_posts('post_id=790&post_type=homepage');
while (have_posts()): the_post();
?>
<h1><?php the_title(); ?></h1>
<div class="cont1-border"></div>
<p><?php echo(types_render_field("homepage-content", array("raw"=>"true"))); ?></p>
<h2><?php echo(types_render_field("homepage-urltitle", array("raw"=>"true"))); ?></h2>
</div>
<div class="left-cont1-image1"><?php echo get_the_post_thumbnail($page->ID, 'home-circle'); ?></div>
<?php endwhile;?>
</div>
Thanks
You should be able to take your current code, change get_the_post_thumbnail($page->ID, 'home-circle') to get_the_post_thumbnail(get_the_id(), 'home-circle'), and replicate your code for each post you want to pull in, modifying the post_id=xxx to match the ID of the post you want to pull in.
This is not the most attractive solution, but from the information you gave, it should at least work. Just so you know, there is an entire StackExchange site devoted to Wordpress: https://wordpress.stackexchange.com/ where you should be able to get more Wordpress-specific answers. If your question is about PHP, please feel free to ask here, but if it is Wordpress-specific, your better bet would be the dedicated Wordpress site.
Since you're new to PHP, I would recommend getting an introductory book or two and try to get some of the basic concepts down pat before working with WordPress. While there will be a larger up-front investment of time, it will pay off in the long run. Good luck!

Using columns in Wordpress page that include header

I'm a little bit of a newb when it comes to PHP, but know enough to get around and would like to know if this can be done. sample
I want to break my wordpress page into 2 columns, but also want to have the header in the 1st column.... along with other text. I don't want the header floating over both columns...
The second column will house images only...
is that possible? In my head it makes sense, but then when I try and work it out, I'm just not sure....
And I just got thinking... I have my home page static with the smooth slider on it, so that is now going to cause more grief.
Any help, advice or pointers would be greatly appreciated.
Thanks in advance
This is more CSS/HTML than PHP, however that's fine. The first thing you need to do is understand how to make a two column layout. Then you will need to have the post title in the first column, something like this:
<article>
<div id="col1">
<h1>Post Title</h1>
Lorem ipsum dolor sit amet...
</div>
<div id="col2">
<img src="" />
</div>
</article>
To make this into WordPress you will of course need to add the WordPress Tags:
<div id="col1">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
Finally, adding the image(s) on the right. It can be done easily using WordPress' built in functionality, if you only need one image: (Note you will have to add something in your theme's functions.php file as per the WordPress Docs)
<div id="col2">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
To add multiple images, it gets more complex and you'll have to start looking for a plugin to achieve that goal.

Wordpress and Internal Page Links

I'm trying to construct a Table of Content on a custom template in Wordpress. Because I already know beforehand the headings of the internal sections I want to link to I hardcoded that into the template.
My problem is that in Wordpress it doesn't scroll to that section at all? Here's the link to a page with an existing TOC section that's not working.
In terms of code, this is an illustration of what I got:
<div class="table_content">
<h4>Table of Contents</h4>
<ol>
<li>Overview</li>
</ol>
</div>
Which should link to an internal section with the code:
<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>
Note: I'm using "ID" instead of "name" because it's deprecated in HTML5, which is the doctype I'm using.
I'm also wondering is there an easier way of doing this with jQuery?
Any help in saving my hairline would be GREATLY appreciated...
Nevermind, I'm a muppet.
It's got nothing to do with doctypes or Wordpress issues. Just my incorrect, sleep-deprived implementation of HTML.
This
<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>
should be
<h2><a id="test_link" class="internal"><?php the_title(); ?></a></h2>
Notice the missing "#" in the "ID" attribute, removing that makes everything work nicely :)
You don't need the separate a element...
http://www.yourhtmlsource.com/text/internallinks.html

Categories