Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What is the best way in smarty to create a function to parse a name?
example:
I have the variable {$attachment.filename}
If the file name is .jpg|.jpeg|.gif|.png
--- my result --- (option to open in lightbox... else no option to open in lightbox...)
Thanks!
Do the parsing in PHP and set a flag in a Smarty variable. In the template check the flag and display what you need. Don't embed logic in templates.
If you really need this functionality in many templates you can, indeed, write a Smarty plugin that suits your needs.
The documentation about Smarty plugins includes examples that can inspire you.
For example:
// Define the function that implements the plugin
function my_special_img($params, Smarty_Internal_Template $template)
{
$src = $params['src'];
// Based on $src decide here if you want lightbox or not
$lightbox = TRUE; // or FALSE
// Generate the <img> element
// Get information from $params, put default values, do whatever you want
$output = implode(' ', array( // build the string from pieces
'<img',
'src="{$src}"',
'width="{$params['width']}"',
'height="{$params['height']"',
'alt="{$params['alt']}"',
'class="{$params['class']}"',
($lightbox ? 'rel="lightbox"' : ''),
'/>'
));
// Smarty will replace the function call in the template with the value it returns
return $output;
}
// Register the plugin in Smarty
$smarty->registerPlugin('function', 'image', 'my_special_img');
In the templates, replace
<img src="filename.jpg" width="40" alt="bla-bla" etc>
with
{image src="filename.jpg" width="40" alt="bla-bla" etc}
That's all. Express your creativity in the plugin's code but keep it simple and use only the values provided in $params.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have created a new user role named student_role I want to redirect the user with this role to form page(which I created from wp front end) when he logs in.
I tried peter login redirect plugin but failed.
Try this :
function rohil_login_redirect_based_on_roles($user_login, $user) {
if( in_array( 'student_role',$user->roles ) ){
exit( wp_redirect('Your page link goes here' ) );
}
}
add_action( 'wp_login', 'rohil_login_redirect_based_on_roles', 10, 2);
Explanation
If you look at the codex, you will find that wp_login provides two parameter: 1) $user_login which will return a string and 2) $user will return an object containing all the details.
But you need to make sure that you also pass priority to that parameters otherwise It will give you an error.
If you want to see what data are into that parameter, you can run below code for learning purpose only.
function rohil_login_redirect_based_on_roles($user_login, $user) {
var_dump($user); // Will give you an object
var_dump($user_login); //Will give you a string
die();
}
add_action( 'wp_login', 'rohil_login_redirect_based_on_roles', 10, 2);
Make sure you delete above code from functions.php after checking what data it contains
So as you can $user object contains roles which shows current logged in user's role. So I simple checked that if($user->roles[0] === 'student_role') if current logged in user is having student_role then wp_redirect('Your page link goes here') redirect them to some page.
Let me know if you have any doubt.
**also posted on druapl.stackexchange
https://drupal.stackexchange.com/questions/150500/giving-custom-argument-vlue-in-q-variable
**
apologies if question is ambiguous . the scenario is as follows:
in drupal 7 , we want to use a custom template page when a specific value is given for the q variable in url .
for example if we give http://localhost/drupal/?q=xyz/123 , we want to use a custom template page say page-xyz.tpl.php ..
have a hunch that hooks and template.php file may be the key components here but not sure what to exactly do..
any help appreciated.
you could implement theme_preproccess_page() (or node, or html) to control this in your template.php
function YOURTHEME_preproccess_page(&$vars) {
if (isset($_GET['q']) && $_GET['q'] == 'xyz/123') {
$vars['theme_hook_suggestions'][] = 'page_xyz';
}
}
that should work, but I would like to recommend not use the '?q=xyz' solution, but do an preproccess that should work to all your pages, like this.
function YOURTHEME_preproccess_page(&$vars) {
$title = strreplace(' ','_', $vars['node']->title);
//if you use the transliteration module, instead of strreplace
//use transliteration_get($vars['node']->title);
$vars['theme_hook_suggestions'][] = 'page_'.$title;
}
now that should work for every page that you want to make a custom template. Just add the file and clear the chaches. If you don't have the page template to the specific page, it's ok, drupal will use the default.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
My requirement is to do SEO Friendly URL for an existing site in Wordpress.
For example,
Current URL: http://localhost/test/?pid=19971
that is the page "test" is rendering the data from some custom plugin.
My new SEO URL : http://localhost/brand/sub_category/product_name
Here, Brand, Sub_category and product_name is fetched from the pid..
I am populating the data using the following rewrite rule from functions.php,
add_rewrite_rule(MY_DYNAMICALLY_POPULATED_URL.'$ page-test.php?brand='.$brand_name.'&sub='.$sub_category.'&pname='.$product_name.' [L]', 'top');
In this code, the page-test.php is placed in the root directory and the data is rendered from that file by passing the brand_name, sub_category and productname to fetch the pid. So based on the pid each product page is rendered.
This code is working fine for me, When I save the data automatically the data is written in .htaccess and page is rendering with the new SEO URL.
But when my client needs it to do it by FALLBACK in Apache instead of add_rewrite_rule due to some load balancing issue.
So can anyone help me how to do the same with Fallback resource.
This fixed my issue.
function my_query_vars($vars)
{
$my_vars = array( 'PARAMETERS' );
return array_merge($my_vars, $vars);
}
add_filter('query_vars', 'my_query_vars');
function my_rewrite_rules($rules)
{
global $wp_rewrite;
$my_page = 'PAGESLUG';
$my_rule = array( 'URL/?' => 'index.php?pagename=' . $my_page . '&school_type=$matches[1]' );
return array_merge($my_rule, $rules);
}
add_filter('page_rewrite_rules', 'my_rewrite_rules');
I'm poor php developer and i need code for my template.php to set specific template for some pages:
Example:
mypage/blog/about-me
mypage/blog/about-you
mypage/blog/about-us
Uses page--blog-about-first.tpl.php.
mypage/blog/about-him
mypage/blog/about-her
mypage/blog/about-them
Uses page--blog-about-second.tpl.php.
I can't find it anywhere so i'm asking here.
Check the naming conventions here:
https://drupal.org/node/1089656
If you need to do something more complex you can use the instructions here/:
https://drupal.org/node/223440#custom-suggestions
// Page template suggestions based off URL alias
$alias=drupal_get_path_alias($_GET['q']);
$args=explode('/', $alias);
if ($args[0]=='blog/about-me') {
$vars['theme_hook_suggestions'][] = 'page__simple_blog';
}
elseif ($args[0]=='artist') {
$vars['theme_hook_suggestions'][] = 'page__simple_blog';
}
This is the code. I got link /blog/about-me and link /artist. Suggestion works for artist page, but not for blog/about-me. Solution?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hi i am totally new here and title says it all ..
i want to reply to a tweet using abraham/twitteroauth library for twitter .. update for the twitte is working fine but i am unable to do reply thing .
I am doing this ..
$status = $connection->post('statuses/update', array("status" =>
$dataa, "in_reply_to_status_id" =>$id));
twitteroauth_row('statuses/update', $status, $connection->http_code,
$parameters);
this code also updates the account with value in $dataa variable but do not reply to the tweet defined in $id
Please help .
Sorry for my bad english .This is my first post.
Thanks
yap . there was mistake from my side while updating the post .. after reading api document .. i found that without #username sign to perticular user it won't appear in his reply section ..
hamdoulilah the solution is so easy
you need just to add #username for who you want to replay to
$status_id = '480775609728385024';
$twitt_reply = '#username the replay text';
$responce = $connection->post('statuses/update', array('in_reply_to_status_id'=> $status_id , 'status' => $twitt_reply ));