PHP CMS not working after change of directory - php

I built(using a tutorial) my CMS in a sub directory on my server and it worked fine. Admin, Archive, full display and synopsis.
I then moved all of this into my main directory, changed the index.php filename to another and used 'include' to display it within a DIV of another page.
It displays the main index.php element of the page but doesn't return articles when they are clicked.
I have searched through the files to change any instances of 'index.php' in the code but there are none.
All admin functions working perfectly and the output URL onclick of blog entry is the same as the previous files in the previous directory. Of course without formatting but that is no problem.
In what part did I make a mistake? I would like to avoid using an iframe to resolve this issue.
The code that the index.php file is including. (homepage.php)
<?php include "templates/include/header.php" ?>
<ul id="headlines">
<?php foreach ( $results['articles'] as $article ) { ?>
<li>
<h2>
<span class="pubDate"><?php echo date('j F', $article->publicationDate)?></span><?php echo htmlspecialchars( $article->title )?>
</h2>
<p class="summary">
<?php if ( $imagePath = $article->getImagePath( IMG_TYPE_THUMB ) ) { ?>
<img class="articleImageThumb" src="<?php echo $imagePath?>" alt="Article Thumbnail" />
<?php } ?>
<?php echo htmlspecialchars( $article->summary )?>
</p>
</li>
<?php } ?>
</ul>
<p>Archivo de Articulos</p>
<?php include "templates/include/footer.php" ?>

Related

How to call one line of text from a php file to use in another?

I'm trying to use the title of an article in one place and be able to place it anywhere by calling it from the php file.
I tried to include the code from news.php and echo it in the footer, but it doesn't seem to work. What am I doing wrong?
news.php
<div class="entry-title">
<h4>
<a href="news/news-article-5-21-2019">
<?php $str1 = "NEWS TITLE" ?></a>
</h4>
</div>
footer.php
<div class="entry-title">
<h4>
<a href="news/news-article-5-21-2019">
<?php include
'news.php';
echo $str1;
?></a>
</h4>
</div>
I expected footer.php to output the "NEWS TITLE" from news.php, but didn't get anything.

Wordpress div not showing on localhost version of site

I've got 2 versions of a site, a live testing version and a local version.
I'm currently working on the local version, using MAMP. The backend of both sites is identical, I've ensured that the admin of each site is exactly the same.
I'm trying to add images to the site via the Edit Page section, but the images aren't displaying.
I inspected the site to see any errors, none were found, however I came acrosss something interesting.
After comparing the html markup of the 2 site versions side by side, I noticed that my local version is missing the the div that displays images.
Here is the div on the live version -
Here is the my local version, in which the div is not being shown -
As you can see in the local version there is a ul instead of div class="image-16-8.
Here is the php file that is displaying these images
<?php
function tbhHeroShortcode($atts)
{
$values = shortcode_atts(array(
'images' => '',
'first-line' => '',
'second-line' => '',
'video' => '',
'link' => '',
), $atts);
ob_start();
?>
<div class="hero">
<?
$images = decode_shortcode_data($values['images']);
if ($images): ?>
<ul data-simple-slider>
<?php foreach ($images as $image): ?>
<li>
<div class="image-16-8" style="background-image: url(<?= $image->url; ?>); "></div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div class="hero-content">
<div class="hero-content-first-line">
<h1 class="header"><?= decode_shortcode_data($values['first-line']) ?></h1>
</div>
<h1 class="italic-header"><?= decode_shortcode_data($values['second-line']) ?></h1>
<div class="hero-content-cta">
<a class="hollow-button" href="<?= decode_shortcode_data($values['link']) ?>">Learn More</a>
</div>
</div>
<?php if (count($images) > 1): ?>
<div class="hero-controls">
<i class="fa fa-chevron-left hero-controls__left" aria-hidden="true"></i>
<i class="fa fa-chevron-right hero-controls__right" aria-hidden="true"></i>
</div>
<?php endif; ?>
</div>
<?php
$component = ob_get_contents();
ob_end_clean();
return $component;
}
add_shortcode('tbhHero', 'tbhHeroShortcode');
Does anyone have any idea of why this is happening?
Well the ul is showing because it's right there in your php
<div class="hero">
<?
$images = decode_shortcode_data($values['images']);
if ($images): ?>
<ul data-simple-slider>
However, on your screenshot from the live version your hero div is different, it looks like this
<div class="hero" id>
The output you are seeing is not being generated by the same file, so either there is some browser/server caching going on and what you are seeing from the live site doesnt reflect the current state of your php, or somehow your php file updates are out of sync between your two environments.
I would guess that the difference between the two sites is in the "edit page" area of whatever page is serving as the home page. I would expect that local version has a shortcode called [tbh-hero] on it with image listed, while the other one doesn't have any images listed or perhaps doesn't have a shortcode on it at all. But, honestly, there are a lot of ways that that code could be implemented within the structure of a given theme.

php - open href like page to specific position

I'd like to know if it's possible to open a page (id=26) at a specific position: .
At the front page i'm using this code at the php file to make the title link to the page
<a href="<?php echo get_page_link(26); ?>">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
Yes, you can use DOM selectors such as #maincontent. You would need to assign an ID to a section on the page and then append it to the trigger URL.
For ex: http://yourdomain.com/index.html#maincontent would take you to that div on the page.
First, in the content of that page (id=26), you need to add an id attribute to some tag, like so:
<div id="myposition">
...
</div>
Next, append #myposition after the get_page_link(26) call:
<a href="<?php echo get_page_link(26); ?>#myposition">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
And you are done.
<div name="position">
content
</div>
link
example:
if you click the link below you will open this page at #new-answer position
link

get file name for url php

I wanted to know how to get the current file name in PHP to be able to load the same file in a different directory.
index.php
works.php
lang/de/
index.php
works.php
lang/pl/
index.php
works.php
<div id="language">
EN
<a class="lang" href="index.php">DE</a>
<a class="lang" href="../pl/index.php">PL</a>
</div>
The current method is redirecting the lang URL, allways to index.php.
I would love to know how to redirect from works.php to lang/de/works.php without redirecting to lang/de/index.php
Sorry if i'm getting you confused
I think this is what you want:
<?php
$page = basename($_SERVER['PHP_SELF']);
?>
<div id="language">
EN
<a class="lang" href="<?php echo $page;?>">DE</a>
<a class="lang" href="../pl/<?php echo $page;?>">PL</a>
</div>
You would save the current file name in the $page variable. Then echo it out and replace index.php in your links.
You should really google this stuff.
<?php basename($_SERVER['PHP_SELF']); ?>
GOOGLE
Now that you added some code, here ya go.
<div id="language">
EN
<a class="lang" href="<?php echo basename($_SERVER['PHP_SELF']); ?>">DE</a>
<a class="lang" href="../pl/<?php echo basename($_SERVER['PHP_SELF']); ?>">PL</a>
</div>
FYI, basename($_SERVER['PHP_SELF']); get's the name of the current file and returns just that. In other words, it will return "index.php" or "works.php"

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