Need help echoing an include that is linked to another echo - php

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();

Related

Different logo on each categories

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.

Wordpress Different Image per footer

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>

How to load page template and put content into?

Maybe it's duplicate but I don't know how it calls and cannot find. I need to load a php-file (template of my block) and set content into it.
For example, template file:
<?php include_once 'boot.inc' ?>
<div class="widget">
<div class="widget-title">I need to put title here</div>
<div class="widget-body">I need to put content here</div>
</div>
And php function to insert new block with this template:
function nm_new_block($title, $content) {};
Can I do it in php?
1° Solution: You need to change you code into:
<?php include_once 'boot.inc' ?>
<?php include_once 'template.php' ?>
<div class="widget">
<div class="widget-title"><?php echo $title; ?></div>
<div class="widget-body"><?php echo $content; ?></div>
</div>
In template.php file you must have something like this:
<?php
$title="My Title";
$content="My Content";
?>
And you don't need function for this cause variables are stored in template.php
2° Solution: You need to implement a function to retrieve variables from external source:
<?php include_once 'boot.inc' ?>
<?php include 'functions.php' ?>
<div class="widget">
<div class="widget-title"><?php echoTitle(); ?></div>
<div class="widget-body"><?php echoContent(); ?></div>
</div>
In functions.php
<?php
function echoTitle(){
$title = 'Add code to get title here';
echo $title;
}
function echoContent(){
$content = 'Add code to get content here';
echo $content;
}
Replace Add code to get title here and Add code to get content here with code to get contents ex:
$title = $_POST['title']; supposing you want get title by a submission form
I do not have enough details to tell you more.

Generate Multiple Divs within php code

Currently I am trying to loop through a directory grabbing all 14 file names and generate some html using the file names. I have run into some issue of creating HTML elements within PHP, and right now I'm just trying to generate an HTML div with an image in it and a line of text underneath 14 times.
I have tried putting empty php tags before and after the HTML elements, which didn't work because PHP does not allow php elements within another php element.
<?php
$dir = "classes/1961/*";
foreach(glob($dir) as $file)
{
<?php
?>
<div class="cell-1-9">
<img src="images/image.jpg">
<p>Dylan Miller</p>
</div>
<?php
?>
}
?>
I need another way of generating HTML elements within PHP.
You just need to close the <?php tag in order to revert back to html:
<?php
$dir = "classes/1961/*";
foreach(glob($dir) as $file)
{
?>
<div class="cell-1-9">
<img src="<?php echo $file ?>">
<p>Dylan Miller</p>
</div>
<?php
}
?>
<?php
$dir = "classes/1961/*";
foreach(glob($dir) as $file)
{
?>
<div class="cell-1-9">
<img src="images/image.jpg">
<p>Dylan Miller</p>
</div>
<?php
}
?>
Try the HEREDOC syntax.
I'm pasting the user1477388's corrected code: the closing HTML; must NOT be indented.
<?php
$dir = "classes/1961/*";
foreach(glob($dir) as $file)
{
echo <<<HTML
<div class="cell-1-9">
<img src="{$file}">
<p>{$file}</p>
</div>
HTML;
}
?>
As shown in the example in my MVC project, PHP-One, you can do something like this using what's known as HEREDOC syntax:
<?php
foreach($Model as $movie)
{
echo <<<HTML
<li class="list-group-item">
<strong>{$movie->Title}</strong> ({$movie->Rating}) - {$movie->ReleaseDate}
</li>
HTML;
}
?>
Adapted for your code, try something like:
<?php
$dir = "classes/1961/*";
foreach(glob($dir) as $file)
{
echo <<<HTML
<div class="cell-1-9">
<img src="{$file}">
<p>{$file}</p>
</div>
HTML;
}
?>
Ref. https://github.com/DominicArchual/Php-One#define-your-view
Footnote: Learning MVC will make you a better developer; also more valuable.

image url in database not displaying in php

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;

Categories