Multiple page ids in an array - php

I'm fairly new to PHP so go easy.
<?php
$body_classes = get_body_class();
$ScanL="url";
if(in_array('parent-pageid-385', $body_classes))
{
echo '<img src="'. $ScanL.'/images/product-logos/image1.gif" />';
}
else if(in_array('parent-pageid-394', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image2.gif" />';
}
else if(in_array('parent-pageid-238', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image3.gif" />';
}
else if(in_array('parent-pageid-382', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image4.gif" />';
}
else if(in_array('page-id-391', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image5.gif" />';
}
else if (in_array('page-id-334', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image6.gif" />';
}
if(in_array('parent-pageid-385', $body_classes))
I need the above to be applied to more than one page id - I tried adding , '' but that broke the code and also tried or / ||
I'm sure I'm probably missing something obvious.
Thanks,

Related

How to concatenate sql, html and php with this code

Basically it is an element which shows an image from the path on database. But I just can't make it work.
<img class="img-circle profile_img" id="blah" src=" <?php $query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
while($row2=mysqli_fetch_array($query2)){
if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
echo '<img class="image--cover" id="blah" src="'.$row2['img_local'].'" alt="Avatar" title="DEFINIDA" onerror="this.onerror=null;this.src=1.png;">';
} else {
echo 'Show a default image.'; // <img src="path_to_default_image" alt="Default_image"/>
}
} ?>" alt="Avatar" title="DEFINIDA" >
I have managed to work, the final code:
<?php
$query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
while($row2=mysqli_fetch_array($query2)){
if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
echo '<img class="image--profile" src="'.$row2['img_local'].'" title="Clique para abrir seu perfil">';
} else {
echo '<img class="image--profile" src="images/user.png">';
}
}
?>

Center the image in PHP

i have this code. how i can make the image be at the center and the text make it more bigger?
if ($spell_checker->check_word($_GET['wordtext'])) {
echo '<img src="images/betul.jpg" width="100" height="100" >'.'<br />';
echo 'Tahniah, Ejaan Anda Tepat Sekali!';
}
else {
echo '<img src="images/salah.jpg" width="100" height="100">'.'<br />';
echo 'Opss.Ejaan Yang Betul Ialah: ';
print_r(implode($spell_checker->suggest($_GET['wordtext'])));
}

Howto modify this short php-function? (Wordpress)

This function is part of the WMPL-Plugin (Language-Selector) for Wordpress. What I need is a extension (if / else) of this function which makes it possible to show another flag-image on active sites.
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active']) echo '<a href="'.$l['url'].'">';
echo '<img src="'.$l['country_flag_url'].'" height="12"
alt="'.$l['language_code'].'" width="18" />';
if(!$l['active']) echo '</a>';
}
}
}
The CSS isn't a problem, but my php-skills are on a very low level. It would be great if anyone can tell me a solution. Thanks for your helping me!
I believe this should do the trick:
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active']) echo '<a href="'.$l['url'].'">';
if($l['active']){
echo '<img src="'.ACTIVE_FLAG_URL.'" height="12" alt="'.$l['language_code'].'" width="18" />';
}else{
echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
}
if(!$l['active']) echo '</a>';
}
}
}
You need to substitute "ACTIVE_FLAG_URL" with your own URL.

IF/ELSE to echo image in PHP

I am trying to echo a specific image based on the results of a IF/ELSE statement, however I can't quite work out the phrasing of the IF/ELSE statement. I'm a relative newbie to PHP, so I'm sure that it's just a little error in the code somewhere, but if anyone could offer any assistance, I'd be grateful!
I'm currently at the stage below:
<?php
$fresh = if ($reviews['reviews']['freshness']) = 'fresh' {
echo '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh" />';
} else {
echo '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
?>
<?php
foreach($reviews['reviews'] as $rv){
if ($tmp++ < 10);
echo $fresh;
echo '<li>' . $rv['quote'] . '</li>';
}
?>
Thank you!
you cant assign if statement to a value.
if ($reviews['reviews']['freshness'] == 'fresh') {
echo '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh"/>';
} else {
echo '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
another prettier way would be:
if ($reviews['reviews']['freshness'] == 'fresh') {
$image = "fresh";
}
else {
$image = "rotten";
}
echo '<img src="assets/images/' . $image . '.png" class="rating" title="Rotten" alt="Rotten" />';
Yup, your code is pretty wrong, but I can see what you're trying to do.
<?php
if ($reviews['reviews']['freshness'] == 'fresh') {
$image = '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh" />';
} else {
$image = '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
?>
Your main mistake there is the incorrect positioning of brackets, and the fact that the IF statement does NOT return a value in PHP.
That said, I'm not sure why you're doing your foreach loop underneath, so I've not touched that; perhaps you could explain further what you're trying to achieve?
This might help you in the right direction:
<?php
if ($reviews['reviews']['freshness'] == 'fresh'){
echo '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh" />';
}
else{
echo '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
while($reviews['reviews']){
for($i=0;i<10;i++{
echo // What do you actually want to print out?
echo '<li>'.$reviews['reviews']['quote'].'</li>';
}
}
?>
I think this is what you're wanting...
<?php
for ($tmp = 0; $tmp < 10 && $tmp < count($reviews); $tmp++) {
if ($reviews[$tmp]['freshness'] == 'fresh') {
echo '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh" />';
} else {
echo '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
echo '<li>' . $reviews[$tmp]['quote'] . '</li>';
}
?>
ETA: Looked at the API and fixed a couple things.
ETAx2: For those wanting to see an example of the JSON return from the API...
{
"total": 41,
"reviews": [
{
"critic": "Joe Baltake",
"date": "2010-07-27",
"freshness": "fresh",
"publication": "Passionate Moviegoer",
"quote": "'Toy Story 3': Alternately affecting, hilarious and heartbreaking and the most original prison-escape movie ever made",
"links": {
"review": "http://thepassionatemoviegoer.blogspot.com/2010/07/perfectimperfect.html"
}
},
{
"critic": "Rafer Guzman",
"date": "2010-07-06",
"freshness": "fresh",
"publication": "Newsday",
"quote": "It's sadder and scarier than its predecessors, but it also may be the most important chapter in the tale.",
"links": {
"review": "http://www.newsday.com/entertainment/movies/toy-story-3-andy-grows-up-1.2028598"
}
},
{
"critic": "Richard Roeper",
"date": "2010-06-30",
"original_score": "5/5",
"freshness": "fresh",
"publication": "Richard Roeper.com",
"quote": "The best movie of the year so far.",
"links": {
"review": "http://www.richardroeper.com/reviews/toystory3.aspx"
}
},
...
Through trial and error, I found the following solution.
<?php
$ID=$row_RecordsetLast['ID'];
$image = '../../pics/'.$ID.'.jpg';
if (file_exists($image)) {
echo '<img src="../../pics/' . $ID . '.jpg" alt="" width="110" height="161" />';
} else {
echo '<img src="guest.png" alt="" width="110" height="161" />';
}
?>

displaying a post thumbnail depending on category in Wordpress?

Is it possible to display a specific post thumbnail image based on the category ID, something like this:
<?php if ( has_post_thumbnail() ) {
if ( cat = 2 ) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} elseif( cat = 3 ) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />'
}
?>
You may want to look into category templates: http://codex.wordpress.org/Category_Templates
The quick solution would be something like this:
if (is_category('1')) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} else if (is_category('2')) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />';
}
//you can also do this by name
if (is_category('Category A')) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} else if (is_category('Category B')) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />';
}
is_category function reference: http://codex.wordpress.org/Function_Reference/is_category

Categories