Using t() in Drupal 7 - drupal

I've searched how to do it a week, but haven't success and it's been a bottleneck in the work so, I decided to ask.
I put <h3><?php print t("strings translation"); ?></h3> in page.tpl.php and flush all caches and reload every languages available in the site.
And then I try to search for the string in /admin/config/regional/translate/i18n_string the options available are Fields, Node types, Menu, Taxonomy, Blocks.
But then I can't find the "strings translation" in /admin/config/regional/translate/translate.
I have read in drupal.org documentation but it seems like I'm missing something.
Could you please advice how to do it?

Here is the way:
1) Drupal should know that a string is 'not translated'. To make it aware of this, you need to visit the page having the string and change the language. Once you do, Drupal will be aware of all those strings on the page which are not translated to the language selected currently.
2) Go to translate page, search for the string, it should now appear there

Are you missing echo in your code?
<h3><?php echo t("strings translation"); ?></h3>
I am not clear what are you looking for. But Stringoverrides modeule may solve your problem. It can translate any string across the project. But, if the string is inside t() function.

Related

Passing arguments to WordPress feed URL

As we all know the WordPress' feed url is www.mysite.com/feed.
I have edited the feed-rss2.php file to show thumbnails if a certain GET parameter is passed. See the code below:
<?php if($_GET['c'] == 'detailswiththumb') echo the_post_thumbnail( array(100,100) ); ?>
But when I open the feed address like this:
www.mysite.com/feed?c=detailswiththumb
The code doesn't work. Can the arguments be passed this way? Am I missing something? Please help.
Firstly, the function is get_the_post_thumbnail() not the_post_thumbnail().
Then, their is one more problem in your code, that you have to pass the post id to get its thumbnail (for more info see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail).
So, first you will have to extract the post id from somewhere and then only you would be able to get the thumbnail. But, I think it would be very tough, so try giving up this thought, for it would take you a lot of time and no living being is going to access that path.
There were browser cache issues. Even with Google Chrome's incognito window. Had to test it with passing fake arguments like...
www.mysite.com/feed?c=detailswiththumb&fakearguments=123
...to clear the cache. And the code is fine.
Sorry for wasting your time guys.

Wordpress Loop get_the_id()

I tried the following functions in header.php, footer.php, single.php etc.
var_dump(in_the_loop());
var_dump(get_the_id());
The first function gives false (meaning we are not in the loop) and the second function gives the post id every single time.
Description of get_the_id() from wordpress :
Retrieve the numeric ID of the current post. This tag must be within The Loop.
I just want a simple explanation what the hell is going on why do i get the post id if I call the function out of the loop !?
must is a little strong for get_the_id() ...delivers evil eye to Wordpress.
It works in the header and non-loop (confirmed).
Please note that post/page are essentially interchangeable in this conversation.
Think of WP this way -> You always have a post id in some way, all the time, every page, unless you do weird stuff or talk about non-page edge cases. When you are at the install root (such as site.com/) there are posts being called, something has to be displayed. There are other settings that will impact post/page such as static front page settings. On a category listing, if there are pages, I got the first ID returned before the loop.
On post/pages the page ID is (more or less0 set before the loop. This is a result of the URL (pretty or ?p=123 format) dictating the content. Using pretty names, the page at site.com/foo-bar/ will try to look up if there is content available via the permalink rules for "foo-bar". If there is content, the post ID is obtained. (simplified)
Later in the page build you get into the loop. However, before the loop you are also offered opportunities to change, sort, or augment the loop - such as changing the page IDs to be looped or sorting.
Regarding in_the_loop(), WP says
"True if caller is within loop, false if loop hasn't started or has ended." via http://codex.wordpress.org/Function_Reference/in_the_loop
in_the_loop() evaluates if the loop is in action (loop being key to the WP world). Also important - when you are in the loop WP can iterate over multiple page/post (IDs).
I don't have a 100% bulletproof explanation as to how the ID always shows, but when you dig into the API and various methods for hooking this might be a result.
I understand your confusion and agree with you. I think WP intended get_the_id() as a loop based tool, outside the loop you will get unpredictable results.
Hope that helps, I do enjoy working in WP, and I hope you do to.

drupal page.tpl.php content variable?

The print $content statement in page.tpl.php . I want to alter it but I can't figure out what/where is the source of the $content variable in page.tpl.php file.
I'd appreciate any help. Thanks.
the drupal version is 6,
This is the return value of menu_execute_active_handler(). You can't change it in Drupal 6. You need Drupal 7 hook_page_alter() for that. Now, preprocess helps a little, see http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/6
chx's answer is correct. This is just a longer explanation.
$content depends on the URL or more precisely the region that calls the variable.
The URL could be something like node/10, taxonomy/term/1, etc. Each of these paths is associated with menu entry which has a callback function that generates the value of $content.
Take a look at the API docs for more info. http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_get_content/6
The ConTemplate module might provide the sort of control over $content that you are looking for. http://drupal.org/project/contemplate

WordPress: How to link the name of an author to that author's list of posts

I'm setting up a WordPress blog and I can't manage to link an author's name to the list of posts written by that author.
I am using this code:
written by <?php the_author() ?>
But this gives me following error:
Warning: Missing argument 1 for get_author_posts_url(), called in /customers/zinneket.be/zinneket.be/httpd.www/wp-content/themes/zinneket/index.php on line 15 and defined in /customers/zinneket.be/zinneket.be/httpd.www/wp-includes/author-template.php on line 220
Line 15 is of course the one copied above.
Does anyone know the right way to do this?
Thanks a lot.
The documentation makes it fairly clear that you need to provide an argument (to identify what author you're interested in).
From the looks of it, the_author_posts_link() is what you want to use.
Rule of thumb: the_ functions involve the current author/post/page/whatever, get_ functions require you to identify what author/post/page/whatever you are interested in.

Drupal 5: Flag module - display user flagged items in a block

I am aiming to get a list of the current user's flagged items in a block which I can use in my node.tpl.php The functionality required is a "comparison list" of products.
Can anyone with experience of the flag module in D5 point me in the right direction? I essentially want to be able to say:
<?php print $all_current_user_flags ?>
Is there a predefined function for this or will I have to get it out of the database manually? I haven't managed to find much in the documentation about this, and am I bit stuck as to what is the best course of action.
Thanks in advance.
Edit: to anyone still reading this, I've moved over to the session favourites module as it lets anonymous users build a list of favourites.
This works:
<h3>Comparison List</h3>
<?php print views_build_view('page',views_get_view('flag_bookmarks'),$args,true,10,$page); ?>

Resources