I have a page where all links where working properly but all the sudden some links are not working anymore.
I am puzzling myself to undersand why. Nothing really changed. Maybe some css details.
Is there anyone who can give a clue?
Thank you for any help. me abou twhat might have happened.
Francesco
PS sorry forgot to say that looking at the source code the links are there and they work. In design view they just do nothing. They look like normal text.
<div id="centrale"><h1> Upcoming events</h1>
<div class="centrale_event">CLICK HERE TO SEE ALL UPCOMING EVENTS</div>
<p class="line"> </p>
<?php do { ?>
<div class="centrale_event">
<p><img src="<?php echo 'drawings/'.$row_rstevents['event_picture']; ?>" class="float" alt="" /><span class="big"><?php echo $row_rstevents['event_title']; ?></span></p>
<p><strong><em>Starting on <?php echo $row_rstevents['date']; ?></em></strong></p>
<p><strong>Where</strong>: <?php echo $row_rstevents['event_town']; ?></p>
<p><strong>Place</strong>: <?php echo $row_rstevents['place']; ?></p>
<p><?php echo extractFirst($row_rstevents['event_details']); ?> MORE INFO HERE</p>
<p class="line"> </p>
</div>
<?php } while ($row_rstevents = mysql_fetch_assoc($rstevents)); ?>
<div class="centrale_event"><p>CLICK HERE TO SEE ALL UPCOMING EVENTS</p></div>
</div>
Are you using Dreamweaver? I thought you might seeing as you mentioned Design View.. If that's the case then just hit F12 to view in a browser, the design view of DW is pretty lame.
Nothing to do with the link problem, but is there a reason you're using a do {} while () loop to output your database results? Using this construct will output at least one blank event before any actual data shows up, as the first time around the loop, you haven't retrieved any data from the query yet. Any reason you can't do a regular while() { } loop?
Related
Hey fellow WordPress dev's / php masters. Long story short, I am using WordPress (and I never use WordPress - sorry!) and when I go to view the individual post rendered from single.php, the 'have_posts()' function is returning false. The template is rendered and I am not having any issues with the template rendering, I am simply having an issue with 'have_posts()' showing false and not outputting the blog post.
I downloaded WordPress 5.0.3, am running on MAMP and have used this method previously without any issues. All in all, I am trying to really keep my template files organized and I am using get_template_part to retrieve sections of the theme.
My current structure is:
single.php -
<?php
get_template_part('template-parts/blog/_single/blog-post-banner'); // Renders perfect
?>
<div class="light-grey">
<div class="container">
<div class="row no-margin">
<div class="col s12 l9 mb-0-l">
<?php get_template_part('template-parts/blog/_single/blog-post'); // Renders perfect ?>
</div>
<div class="col s12 l3 mb-0-l">
<?php get_template_part('template-parts/blog/side-bar'); // Renders perfect ?>
</div>
</div>
</div>
</div>
And of course the real culprit the blog-post partial -
<?php
if (have_posts()) :
the_post(); ?>
<div class="row no-margin">
<div class="col s12 no-margin relative">
<img src="<?php the_post_thumbnail_url('medium_size'); ?>" alt="<?php the_title(); ?>" class="block">
</div>
<div class="col s12">
<div class="white p-2-s p-3-l">
<?php the_content(); ?>
</div>
</div>
</div>
<?php else :?>
<div class="col s12 no-margin">
<div class="white p-2-s p-3-l"><p>Sorry, we couldn't find the post you were looking for.</p></div>
</div>
<?php endif; ?>
Again, the templates are rendering perfect but the 'have_posts()' is returning false and spitting out my 'else' part of my statement. I have used this method in another template and it worked perfectly before (although I will admit, I love to develop in node and WordPress and php have really made me beat my head against the wall at times lol). Is there something I missed?
I have checked my functions.php which I have written from scratch, and there isn't a single thing in there that might affect the post but if you need to see it, I would be happy to share it (I have disabled each portion of the functions.php to check if it would help and no luck). I don't have any plugins added, not even the default included ones (I am a dork that wants to build most everything from scratch so I know how it works).
Am I wrong in that the output to 'have_posts()' should be true on the single.php page? Did I do something wrong with my partials? The banner does use the 'the_title()' tag and 'the_date()' tag but both php tags are properly closed. Would really appreciate some insight on why I am getting false on this. Thanks everyone!
** EDIT ** - When I went to debug the blog-post partial and var_dump the have_posts(), I placed it above the if statement and everything rendered. Looked like so:
<?php
var_dump(have_posts()); // <---------------- Added this and it rendered
if (have_posts()) :
the_post(); ?>
The var_dump output false but then if I did it a second time, it now renders true. Any ideas as to why? For the time being, I am storing a have_posts() in a random variable so there is no output and the post is now showing. While I am happy the post is now showing, I know this isn't necessarily a 'solid fix'. Any ideas with this?
So first I just want to say, #Jeppe you had it right the whole time. If I could mark your comment correct (and if you can, please show me how) I would.
To anyone else who stumbles across this post, it comes down to using the 'rewind_posts()' function. All in all, I have a loop somewhere in my code, that I can't identify as the culprit, that is essentially forcing my 'have_posts()' function to return false because I haven't reset it / rewound it according to WordPress.
My solution was to simply take my old code:
<?php
if (have_posts) :
the_post;
?>
and add the rewind_posts() function above the if statement:
<?php
rewind_posts(); // <---------- This guy right here.
if (have_posts) :
the_post;
?>
This will rewind WordPress's loop and allow have_posts() to print true.
I am trying to set text to be a link in php, however, it doesn't seem to be doing what I want. I am a newb in php though, so I could be doing it wrong.
The code that I've tried (which seems to be the general census on what to do...) was:
<?php if (get_theme_mod('second_author_desc','') != '') { ?>
<li class="wow fadeInRight" data-wow-duration="2s">
<img src="<?php if (get_theme_mod('second_author_image','') != '') { ?><?php echo get_theme_mod('second_author_image',''); } else { echo get_template_directory_uri(); ?>/images/testimonial-image.png <?php } ?>" onMouseOver="javascript: this.title='';" title="<a class='arrow'></a>
<?php echo get_theme_mod('second_author_desc',''); ?>
<p><a class='testimonial'><?php echo get_theme_mod('second_author_name','') ; ?></a></p>">
</li>
<?php } else { ?>
<li class="wow fadeInRight" data-wow-duration="2s">
<img src="<?php echo get_template_directory_uri(); ?>/images/testimonial-image.png" onMouseOver="javascript: this.title='';" title="<a class='arrow'></a>Follow mutual weirdness on Pinterest for the latest on mental health, making money online, blogging tips, and more!<p><a class='testimonial' >#mwgleason23</a>"</p>
where is starting it in a new paragraph, class is calling the css style, href is telling it to link, the address to link to, and the text that I want hyperlinked.
<a class="testimonial">#mwgleason23</a>
This is what shows up when I right click on the site and point to Inspect (using Chrome). I'm not sure where else to find source information...
Any assistance would be WONDERFUL! And if there is extra coding you need to help me out, just let me know and I'll share whatever you need!
Thanks!
P.S. For those thinking I haven't tried taking care of this myself, I have spent HOURS scouring the internet for an answer, tried everything I came across, and just ended up messing things up more. Hence why I'm here, as a 1-rep newb. Just FYI.
your code close the href midway
<p><a class='testimonial' href="<?php echo 'http://pinterest.com/mwgleason23'; ?>">#mwgleason23</a></p>
try this. the link should work. your doulbe quote "" in echo close the href tag early thus making the link not working so use single quote instead for the php echo statement.
I'm working on a login system for a website in which the top right corner will change depending on whether or not the user is "signed in" (a check against a session variable). I am using the following to try and show only one these two states.
<?php if(isset($_SESSION['id'])): ?>
<div class="large-2 large-offset-5 columns">
<p class="right text-pad-top">#MuffinTheFox</p>
</div>
<div class="large-1 columns">
<img class="avatar" src="https://pbs.twimg.com/profile_images/429861192207982592/lxaKQ4Rp.jpeg">
</div>
<?php else: ?>
<div class="large-2 large-offset-7 columns">
<a class="right text-pad-top" href="login.php">Log in/Sign up</a>
</div>
<div class="large-1 columns">
<img class="avatar" src="http://placehold.it/50x50">
</div>
<?php endif; ?>
The problem is, when I upload the code to my server and run it, both HTML blocks display, regardless of the PHP statements.
There aren't any obvious errors and according to my research into the topic, this should work. Also, I tried the way without the endif; statement as well by using brackets, and that didn't work either. At this point I'm somewhat lost as to why this is happening and any help or insight would be appreciated.
Edit: Something of note, the PHP is embedded into a HTML document with a .html extension. I was under the impression that you could just inline php into a html document without issue, but I have a feeling that this might be the cause of the issue.
Your file is not getting parsed as PHP because PHP is not configured to parse .html files unless you tell it to. See this question for insight into how to do that. In the meantime, change your file extension to .php and it should start working as you expect.
I have a small problem, and I'll try to break it down into a smaller one so I can explain it properly.
I'm working on a web application and I have a couple of divs, such as this:
<div class="1">
//search bar
</div>
<div class="2">
include_once 'actioncontroller.php';
</div>
<div class="3">
</div>
In the actioncontroller.php I'm having an action controller which decides what action to take depending on what's pressed on the page. I've put it in the second div because ultimately that's where I want to print everything.
My question is, is there any way that I can use the code from the second div in the first one, without it printing it there? Basically I want the search bar from div one to do/print the same thing as the one in div 2 does, but I know(think) that PHP can't see code above the include_once, and if I include the actioncontroller.php in the first div it will print it there, instead of printing it in the second one, as I want.
Hope I was clear enough, it's not a problem of coding, it's just a matter of how can I read the script in the first div and then run it in the second one...
Thanks in advance
My question is, is there any way that I can use the code from the second div in the first one, without it printing it there?
Yes, but the best solution is to change the code you've already written. In the long-term, it is vitally important that you minimize your "procedural" PHP code, so that nothing ever happens simply by include/require-ing a file.
Trust me on this, it works for toy project, but it always leads to insanity and pain in the end. For example, don't put this in a file:
<?php
echo("Header section");
This is bad because you have no choice about when it prints. This is a step up:
<?php
function WriteHeader(){
echo("Header section");
}
Even better would be to use classes an autoloading, but that's probably more than you need to hear right now. With that kind of approach, your main page would look more like:
<?php
// This next line simply makes the class ActionController *available*,
// it does NOT cause new things to happen on its own
include_once("actioncontroller.php");
?>
<div class="1">
<?= ActionController::MakeSomeHTML(); ?>
</div>
<div class="2">
<?= ActionController::MakeSomeHTML(); ?>
</div>
<div class="3">
</div>
This code takes the output of actioncontroller.php and saves it into a variable, which can be echo'd multiple times.
<?php
ob_start();
include_once 'actioncontroller.php';
$output = ob_get_contents();
ob_end_clean();
?>
<div class="1">
<?php echo $output; ?>
</div>
<div class="2">
<?php echo $output; ?>
</div>
I am new to the community, and this is my first question so far.
I got stuck an hour ago on this. Session checks if user is logged in or not then displays either login-form_eng.php or logout-form_eng.php with include. Problem is the image shown is displayed 3 times and I am only calling the include function once.
<body>
<div id="full-wrap" class="container-wrap">
<div id="header-wrap" class="secondary-wrap">
<h1 class="linky-logo" title="elcoma.com"></h1>
<div id="main-menu-wrap" class="secondary-wrap">
<table border="0"cellspacing="0"cellpadding="0">
<tr><td>
<a class="linky8"title="Home"onclick="alert('Button Click')">
</td><td>
<a class="linky2"title="News"onclick="alert('Button Click')">
</td><td>
<a class="linky3"title="Products"onclick="alert('Button Click')">
</td><td>
<a class="linky4"title="Services"onclick="alert('Button Click')">
</td><td>
<a class="linky5"title="About Us"onclick="alert('Button Click')">
</td><td>
<a class="linky6"title="Contact"onclick="alert('Button Click')">
</td>
</tr>
</table>
</div>
</div>
<div id="login-logoff-wrap" class="secondary-wrap">
<?php
session_start();
if(isset($_SESSION['user']))
{
echo "Welcome back ". $_SESSION['user']. ". Please enjoy your stay at our site!";
include "logout-form_eng.php";
} else {
echo "Welcome guest. Please log in or register at our site";
include "login-form_eng.php";
}
?>
</div>
</div>
Here is a link to how the problem looks like:
Picture
EDIT
Apparently the two divs around the php script were causing the problem. But I still can't explain why, can somebody explain it to me?
I removed all classes out of all divs one by one then I started deleting the divs. That's how I came to the solution that the two divs around the php login script were somehow "calling" the script? I have no other explanation and I would appreciate a valid one. Thank you!
session_start() should go before all output on the page. The HTML you have preceeding the PHP is considered output.
Since you didn't post the PHP for your two PHP pages, is it possible that there is a redirect in one of these pages that loops back on itself?
Also use include_once() to prevent the page from being included multiple times.
http://php.net/manual/en/function.include-once.php
Check your CSS. Class secondary-wrap is used three times in the DOM. I suppose, that in your CSS the image is used as background in .secondary-wrap.
To solve this, you could stick additional class, say .my-picture to the topmost <div>:
<div id="header-wrap" class="secondary-wrap my-picture">
and move the background image from .secondary-wrap to new .my-picture.
Or just remove class="secondary-wrap" from the two other divs:
<div id="main-menu-wrap" class="secondary-wrap">
and
<div id="login-logoff-wrap" class="secondary-wrap">
if there's no other relevant CSS in this class.