Is it possible to assign
get_theme_mod('dds') !== 'false';
to a variable and include it in an if statement instead of typing the whole thing?
This is the if statement I am dealing with:
$DDS = get_theme_mod('dds') !== 'false';
if( is_category() && $DDS ) :
//output some css style
endif;
I get an error: Parse error: syntax error, unexpected ':'
You get error because of you are not complete if statement bracket see below code to remove error.
$DDS = get_theme_mod('dds') !== 'false';
if( is_category() && $DDS ) :
//output some css style
endif;
Another solution: no need to make variable you can direct add code in if condition you get same solution as above code
if( is_category() && ( get_theme_mod('dds') !== 'false' ) ) :
//output some css style
endif;
Why do you need != false at all, seems redundant?
Related
We have this code to display the custom field in WordPress
if( isset($digi) && !empty($digi) )
Now we want to add a new condition (check in terms of being categorized)
That's how we did it
if( isset(product_categories=55,56,57,58) || isset($digi) && !empty($digi) )
Is it correct?
I am not sure in what file or loop you perform this code, but your solution might be something similair to this:
$your_category = "THE CATEGORY YOU WANT TO CHECK FOR";
$product_categories = array(55,56,57,58);
if( in_array($your_categroy, $product_categories) || ( isset($digi) && !empty($digi) ) )
this is the php code:
<?php
$tid = $job_node->field_job_cv_destination['und'][0]['tid'];
$term = taxonomy_term_load($tid);
$name = $term->name;
?>
and that is the error:
ParseError: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in -
rules_php_eval() (line 2 -/web/maavarim/sites/all/modules/contrib/rules/modules/php.eval.inc(125) : eval()'d code)
can anyonw know what to do?
Try to implement your code as below
function mytheme_preprocess_page(&$vars, $hook) {
if (isset($vars['node']) && in_array($vars['node']->type, array('article', 'column'))) {
// Set header to topic for articles and columns
// #TODO: consider primary topic field (no multiselect), default to below if empty
$term = taxonomy_term_load($vars['node']->field_topic_ref[LANGUAGE_NONE][0]['tid']);
$vars['head_title'] = $term->name;
}
else {
$vars['head_title'] = $vars['title'];
}
}
I have a problem with Oracle DB.
<?php
require_once 'includes/conn.php';
function connect_db()
{
if ($c=oci_pconnect(uname,pwd, host,'AL32UTF8'))
return $c;
else
die( "ERROR");
}
$conn=connect_db();
$query = "BEGIN :ds_id :=DS.REG_DS1(:F_NAME);END;";
$stmt=oci_parse($conn,$query);
$f_name='John Doe';
$ds_id=-1;
oci_bind_by_name($stmt, ":ds_id", $ds_id);
oci_bind_by_name($stmt, ":F_NAME", $f_name);
if(oci_execute($stmt))
{
echo 'good';
}
else
print_r(oci_error($stmt));
?>
Here is function REG_DS1
FUNCTION REG_DS1(F_NAME IN VARCHAR) RETURN NUMBER AS
DS_ID NUMBER(8,0):=9988;
BEGIN
-- INSERT INTO TEST VALUES(F_NAME,SYSDATE);
RETURN DS_ID;
END REG_DS1;
When I try to execute this function from Sql Developer, it runs with no problem.
But if I execute from PHP script above, it gives me error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 [offset] => 0 [sqltext] => BEGIN :ds_id :=DS.REG_DS1(:F_NAME);END; )
If i change DS_ID variable to another number less than 100, it works great from both. but if i set it to a number more than 99, it gets me error from php script.
What can be a problem?
--jst idea and this is not solutioN
variable decleration or some defination problem
oci_connect($ODBuser,$ODBpass,$ODBhost,$db_charset);
should try like this
not like
oci_pconnect(uname,pwd, host,'AL32UTF8')
sample code :
-- just idea
<?php
$file = "../script/param.CML";
$encryptObj = new cast128;
$encryptObj->setkey("SABBIllustrateKey");
$fp=fopen($file,'r');
$strContent = fread($fp, filesize($file));
fclose($fp);
$strContent=$encryptObj->decrypt($strContent);
$ArConnect=split(" ",$strContent);
$OraService=$ArConnect[8];
$OraUser=$ArConnect[9];
$OraDBpass=$ArConnect[10];
$db_charset = 'AL32UTF8';
$cursor=oci_connect($OraUser,$OraDBpass,$OraService,$db_charset);
if(!$cursor)
{
echo "<br>Error In connection:- reason<BR>";
$e = oci_error(); // For oci_connect errors pass no handle
}
?>
<?php
$file = "../script/param.CML";
$encryptObj = new cast128;
$encryptObj->setkey("SABBIllustrateKey");
$fp=fopen($file,'r');
$strContent = fread($fp, filesize($file));
fclose($fp);
$strContent=$encryptObj->decrypt($strContent);
$con=split(" ",$strContent);
$OraService=$con[8];
$OraUser=$con[9];
$OraDBpass=$con[10];
$db_charset = 'AL32UTF8';
$cursor=oci_connect($OraUser,$OraDBpass,$OraService,$db_charset);
if(!$cursor)
{
echo "<br>Error In connection:- reason<BR>";
$e = oci_error(); // For oci_connect errors pass no handle
}
?>
Thx guys, finally I solved problem myself.
The problem was in variable size of returning value
By changing
oci_bind_by_name($stmt, ":ds_id", $ds_id);
to
oci_bind_by_name($stmt, ":ds_id", $ds_id,10,SQLT_INT );
the problem was solved.
I've wrote the following Doctrine query:
$query3 = $this->entityManager
->createQueryBuilder()
->select('t.textDomain , t.translationKey , t.languageIso , t.translationDate')
->from(
'AMDatabase\Entity\TheVerse\TranslationsMasters',
't'
)
->groupBy('t.languageIso')
->orderBy(
't.translationDate',
'DESC'
);
// the values of $key2 array are:
// en-US
// es-MX
// es-PR
foreach( $translation AS $key2=>$value2 ) {
if ( $key2 == 'en-US' ) {
$query3
->orWhere(
$query3->expr()
->like(
't.languageIso',
':languageIso'
)
)
->setParameter(
'languageIso',
$key2
);
}
}
$result3 = $query3->getQuery()
->getArrayResult();
How do I have the query search for all 3 language ISO's at the same time?
With "if ( $key2 == 'en-US' ) {" the query executes and gives me the expected result.
But if I remove "if ( $key2 == 'en-US' ) {" there are no search results.
I thought by using "orWhere" it would keep adding conditions to the query (where en-US will still produce a match).
In haven't ever been able to get orWhere to function the way I think it should. It might be that you need a Where in your opening definition before you can add an orWhere later. You might have to use the nested orX statement like this instead:
$query3->andWhere($query3->expr()->orX(
$query3->expr()->like('t.languageIso', $query3->expr()->literal('en-US')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-MX')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-PR'))
));
You can't develop the statement through a loop. But, since you've only got three criteria, it's easy enough to write out.
I am tasked with i18n-ing our current CMS setup in Drupal.
The problem that I am facing is with use of module_invoke() to place blocks within nodes.
I have managed to string translate blocks, and that is working when a block is placed in a region (block content is successfully translated) using the UI.
However, when a block is injected into a node like such:
$block = module_invoke('block', 'block', 'view', 22); print $block['content'];
It is not getting translated, or even worse, not showing at all.
I have also tried this variation using t(). e.g.:
$block = module_invoke('block', 'block', 'view', 22); print t($block['content']);
to no avail.
Generally speaking I've having a bit of trouble with blocks for i18n. Does anyone have a recommended approach for dealing with blocks in drupal with regards to translating them? I would prefer not to create different blocks for each language.
So .. After digging around in the bowels of Drupal - and much hair pulling .. I've come up with an almost decent solution.
Basically, with this function, I can extract a translated version of a block:
function render_i18n_block($block_id, $region = "hidden"){
if ($list = block_list($region)) {
foreach ($list as $key => $block) {
// $key == <i>module</i>_<i>delta</i>
$key_str = "block_".$block_id;
if ($key_str == $key){
return theme('block', $block);
}
}
}
}
Then, in my node, I simple call:
<?php echo render_i18n_block(<block_id>,<region>); ?>
There can be some issues where your blocks might not be displaying in a region (and therefore you can't pass a region into block_list). For this case, I simply created a region called "hidden" which is not rendered anywhere in my template, but can be used to call block_list.
Finally (and this is the part that I still need to find a good solution for), I discovered that block_list() in: includes/blocks/block.inc has a bit of an issue.
It appears that $theme_key is not reliably set unless block_list() is being called from the theme() function (in includes/themes.inc) .. this causes the SQL to return an empty results set. The SQL looks like this:
$result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));
As you can see, if theme_key is not set, then it will just return an empty result.
For now I am bypassing this by simply adding:
if (!isset($theme_key)){$theme_key="<my_theme_name>";}
in modules/blocks/block.inc::block_list() around line 429 .. I still need to work out a better way to do this.
10 for anyone with suggestions on how I could ensure that $theme_key is set before calling block_list :)
I had exactly the same problem as you, since I was using
$block = module_invoke('block', 'block_view', 'block_id');
print render($block['content']);
to inject the block into my nodes. However, looking up module_invoke in the Drupal reference, I found a comment titled "to render blocks in Drupal 7 better to use Block API", with this code:
function block_render($module, $block_id) {
$block = block_load($module, $block_id);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
return $block_rendered;
}
I just un-functioned it to use directly, like so:
$block = block_load('block', 'block_id');
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
print render($build);
And for me it works like a charm. Be aware however that this method prints the block title as well, so maybe you'll want to set it to 'none' in the original language.
Create a function like this
<?php
function stg_allcontent2($allC, $level
= "1") {
global $language; $lang = $language->language;
foreach ($allC as $acKey => $ac) {
if($ac['link']['options']['langcode']
== $lang){ if ($level == "1")
$toR .= "";
if (is_array($ac['below']))
$class="expanded"; else
$class="leaf";
$toR .= "<li class=\"".$class."\">" . l($ac['link']['link_title'], $ac['link']['link_path']) . "</li>";
if ($level != "1") $toR .= ""; if (is_array($ac['below'])) $toR .= "<ul class=\"menu\">".stg_allcontent2($ac['below'], "2")."</ul>"; if ($level == "1") $toR .= ""; }
}
return $toR; } ?>
call like this
<?php echo '<ul class="menu">'; echo stg_allcontent2(menu_tree_all_data($menu_name
= 'menu-header', $item = NULL)); echo '</ul>'; ?>
This may help you: http://drupal-translation.com/content/translating-block-contents#
UPDATE: the t() function allows you to pass in the language code to use.