I want to change a different logo for a category and it's articles. The category is https://afdigitale.it/category/af-gaming/ and logo: AF-Gaming.png.
I use in functions.php this code but it does not work:
<?php
if (is_category ('6933')) {?>
<img src = "https://afdigitale.it/wp-content/uploads/2018/03/AF-Gaming.png" />
<? Php
}
else { ?>
<img src="https://afdigitale.it/wp-content/uploads/AF-Digitale-logo.png" />
<?php
}
?>
I found php syntax error in your code in line 4.
Heres the correct code:
<?php
if (is_category ('6933')) {?>
<img src = "https://afdigitale.it/wp-content/uploads/2018/03/AF-Gaming.png">
<?php
}
else { ?>
<img src="https://afdigitale.it/wp-content/uploads/AF-Digitale-logo.png">
<?php
}
?>
You can check this code with functions.php but for actual logo replace you may need to use this code in header.php or any other file where original code for logo is written.
Related
I have a WP site and I am trying to achieve the following. I need on 3 different pages a separate image in the footer.
I did find an answer how to do it the following way placing this code in the footer:
<?php
if(is_page(4)):
?>
<div class="images"><img src="url-image-location" alt="alt info" class="img-responsive"></div>
<?php endif; ?>
The above way works great but i'm lost on how to add it for the another page. I tried just repeating the above code again and changing the page and image url but then I lose styling from the rest of footer.
So question is, how do I add it a second time?
Thanks
What about using elseif and just change the image path variable so you won't loose styling? i assume your css is written for class.
<?php
$image_path = "imagepath";
if (is_page(4)) {
$image_path = "imagepath-4";
}
else if (is_page(5)) {
$image_path = "imagepath-5";
}
else if (is_page(6)) {
$image_path = "imagepath-6";
}
?>
<div class="images"><img src="<?php echo $image_path?>" alt="alt info" class="img-responsive"></div>
I have a 3 php files where i am trying to echo an include from a page.php to template.php but the include is another php file (Slideshow.php) it works but is positioned in the wrong place
The result needs to be like this:
http://st-margarets-barking.org.uk/SchoolDay.php
the codes i have are:
template.php:
<body>
<?php echo $slideshow; ?>
</body>
page.php:
<?php
$content = "content";
$slideshow = include("Slideshow.php");
$template = "template.php";
require($template);
?>
Slideshow.php:
<?php echo "<img src='Images/slideshow-frame.png' style='position:relative; top:-20px;'>
<div class='cycle-slideshow slideshow-width' data-cycle-speed='500' data-cycle-timeout='5000'>
<img src=Images/slides/041214%20Assembly%20(5).png>
<img src=Images/slides/Evacuation-Day-001.png>
<img src=Images/slides/Trewern-002.png>
<img src=Images/slides/church-silhouette.png>
<img src=Images/slides/Evacuation-Day-003.png>
</div>";
?>
The result is this:
http://st-margarets-barking.org.uk/SchoolDay0.php
I have tried:
page.php
$slideshow = "<?php include('Slideshow.php');";
However this shows a server error
I can do this:
template.php:
<?php include("Slideshow.php"); ?>
This works, but then I have to create more template.php as well as more Slideshows.php, this is not what I want to do
the point of this is to have different slideshow.php files so I can change the slideshow in the page.php, then the template.php will echo the slideshow and all other content on the page.php, this will save me time of having to change the slideshow images on each page.php
can anyone show me what I am doing wrong?
If you are trying to display the content of Slideshow.php inside template.php, you have to change it like this:
<?php
function images() {
$str = "<img src='Images/slideshow-frame.png' style='position:relative; top:-20px;'>
<div class='cycle-slideshow slideshow-width' data-cycle-speed='500' data-cycle-timeout='5000'>
<img src=Images/slides/041214%20Assembly%20(5).png>
<img src=Images/slides/Evacuation-Day-001.png>
<img src=Images/slides/Trewern-002.png>
<img src=Images/slides/church-silhouette.png>
<img src=Images/slides/Evacuation-Day-003.png>
</div>";
return $str;
}
?>
Then call the method inside page.php like:
include("Slideshow.php");
$slideshow = images();
I'm trying to set a logo in an options panel for Wordpress, where there's the regular logo and the retina logo upload. I want it to work so if there's a retina logo uploaded, use that, but set to the regular logo size. If there is no retina logo but there is the regular logo, use that, otherwise use blog name. My issue is one of php conditionals that I can't quite seem to get right.
The following code produces two logos, the large and the small right now. The second line does properly produce a retinized logo. But I'm missing some kind of else statement? I did try php else in the second statement, but it produced errors.
<?php if (!empty($mandm['logo']['url'])) { ?> <div id="logo"><img src="<?php echo esc_url($mandm['logo']['url']); ?>" alt="<?php bloginfo('name');?>" />
<?php if(!empty($mandm['retina-logo']['url'])) {?> <img src="<?php echo esc_url($mandm['retina-logo']['url']);?>" class="retina-logo" style="max-height:<?php echo $mandm['logo']['height'];?>px" /> <?php } ?></div>
<?php } else { bloginfo('name'); } ?>
</a>
<?php endif; ?>
I am currently creating a CMS.
Currently I have.
* Saved my images in mysql as app_image
* Saved the images as a URL to where the images are located
But creating MY INDEX PAGE only displays my link as a broken URL.
my code for this page:
<?php
include_once('include/connection.php');
include_once('include/article.php');
$article = new article;
$articles = $article->fetch_all();
?>
<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
CMS
<ol>
<?php foreach ($articles as $article) { ?>
<li>
<a href="article.php?id=<?php echo $article['app_id']; ?>">
<img src="<?php echo $article['app_image']; ?>" height"100" width"100">
<?php echo $article['app_title']; ?>
</a> -
<small>
Posted: <?php echo date('l jS', $article['article_timestamp'] ); ?>
</small></li>
<?php } ?>
</ol>
<br><small>admin</small>
</div>
</body>
</html>
Can anyone see how I have gone wrong?
Thanks.
OK, I have done simalar thing and it is working just fine.
The code looks similar, and looks fine by me, now, maybe the link indeed is broken (maybe you didn't input the right upload link in DB)
I would go step by step and check that link (check if it is the right link). (with /path/name.ext)
If it is some help here is my case:
I put in DB post_id,post_title,post_contents, post_link
than i get that info with:
$query = $db->prepare ("SELECT bla bla FROM bla bla ORDER BY id DESC")
$query->execute();
$query->bind_result(everything that is selected seperated with ",");
(including $link)
<?php
while($query->fetch()):
?>
<a href="single-post.html" title="">
<img src="../images/<?php echo $link; ?>">
</a>
<?php
}
?>
NOW, the trick I did (to avoid problem is that i put inside DB only the name of file, the upload path is stored directly in HTML ("../images/")
Your code looks similar, and I think it should work, I think the problem is with link.
Var dump can come to the rescue here. Try this to see what the array key values should be set to for each of the elements in $article.
<?php foreach ($articles as $article) { ?>
echo '<pre>'; //just makes it a bit easier to read
var_dump($article); exit;
I'm working on a website where the homepage has a dark background, yet all the other pages have a white background.
I am using pho to include a header file to show the logo, navbar, telephone details etc on every page.
As the home page has a dark background, the logo has white text, yet the logo use on the other pages has dark text.
I'm looking for a way of using php, so that I include a single header file on every page. If the homepage has a class of "home" the logo image with white text is shown and on all other pages the logo image with dark text is shown.
something along these lines:
if (body class="home") {
<img src="images/logo-with-white-text" />
else {
<img src="images/logo-with-dark-text" />
};
Is this possible?
Any help or advice would be greatly appreciated :)
I'm assuming your homepage currently looks something like this:
<html>
<head>...</head>
<body class="home">
...
<?php include 'header.php'; ?>
...
You could make the class a variable, and reference this variable from the included header file:
<?php $class = 'home'; ?>
<body class="<?php echo $class; ?>">
...
<?php include 'header.php' ?>
...
In header.php:
<?php if (isset($class) && $class == 'home'): ?>
<img src="images/logo-with-white-text" />
<?php else: ?>
<img src="images/logo-with-dark-text" />
<?php endif; ?>
You could check whether you are on the homepage (Depending on your exact implementation) with a snippet like this:
if (basename($_SERVER['SCRIPT_NAME']) == 'index.php') {
// home page
}
else {
// some other page
}
$_SERVER['SCRIPT_NAME'] contains the actually loaded file relative from the host until the query-string:
http://example.com/my/folder.php?a=b => /my/folder.php
For more information have a look at basename in the PHP manual.
$_SERVER['REQUEST_URI'] contains the current page url (after the domain). You could check instead that the page has the homepage url with that.
Depending on your setup you'd have something like
<?php if ($_SERVER['REQUEST_URI'] == '/') : ?>
<img src="images/logo-with-white-text" />
<?php else: ?>
<img src="images/logo-with-white-text" />
<?php endif; ?>
You don't need PHP for this if you use an image replacement technique to display the image.
Basically, you use an <h1> or something for your logo, with text, then use negative text-indent to hide the text, set a height and width, and use a background image for the logo. Example:
http://jsfiddle.net/nwNbb/
<h1 id="logo">My Website</h1>
#logo {
text-indent:-999px;
background:url(/path/to/logo.png);
height:100px;
width:500px;
}
Then, in your CSS, you can change the background image based on the body class:
body.home #logo {
background:url(/path/to/alternate-logo.png);
}
You can actually do image replacement on images as well:
http://jsfiddle.net/nwNbb/3/
img {
/* 500x100 replacement image */
background:url(http://lorempixum.com/500/100);
/* hide original image */
width:0;
height:0;
/* use padding to set width/height of replacement */
padding:50px 250px;
}