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.
Related
I apologize in advance for the horrible title; I'm sure there's a better way to ask this question, but I couldn't come up with it. I'll try to do a better job with an example.
I was recently working on a project in Wordpress using Woocommerce, and needed to create a shortcode in my functions.php file. This was a custom shortcode to display Woocommerce product "cards", each of which needing to be wrapped with a link around them. My issue arose when trying to echo out a link using the_permalink(). What kept happening was the permalink was being displayed on the front end, rather than simply linking the content that I wanted to link. I've heard that this problem can arise when using echo sometimes, although I'm not exactly sure why. Aside from all that, the code worked fine. However, due to the link displaying like it was, I ended up having to use this code:
echo '<div class="featured-products-carousel owl-theme owl-carousel">';
if ( $products_query->have_posts() ) {
while ( $products_query->have_posts() ) : $products_query->the_post();
$thumb_image = kdmfi_get_featured_image_src( 'featured-image-2', 'full' ); ?>
<a href="<?php the_permalink(); ?>" class="featured-link">
<div class="featured-product">
<div class="featured-img">
<?php
if ( isset($thumb_image) ) {
kdmfi_the_featured_image( 'featured-image-2', 'full');
} else {
echo ('<img width="300" height="300" src="' . get_template_directory_uri() . '/images/woocommerce-placeholder.png" class="cat-thumbnail-img cat-placeholder-img" alt="Category Placeholder Image">');
} ?>
</div>
<div class="featured-text">
<div class="featured-product-title"><?php woocommerce_template_loop_product_title(); ?></div>
<div class="featured-product-price"><?php woocommerce_template_single_price(); ?></div>
</div>
</div>
</a>
<?php endwhile;
} else {
echo __( 'No products found' );
}
echo '</div>';
You'll see that on the same line where I declare the variable $thumb_image, I had to close php so that I could use straight HTML for <a href="<?php the_permalink(); ?>">. Originally, I was trying to do it by not closing php and using echo before all my HTML tags, but then I ran into the issue I explained above. Therefore, my question is three-fold:
Why does echo display the_permalink(), rather than just linking it? I also tried get_the_permalink() as well, with the same results.
Is there a better way to get around this problem so that you don't need to close php and then reopen it after your HTML? Or is closing php in this situation and doing what I did best practice? It just seems like there should be a better way.
Where else might echo cause problems like the one I ran into? Is there a clear set of situations where using echo should be avoided in lieu of something else? If so, what are those situations?
Please let me know if any further information is necessary or would be helpful to have in order to answer my questions.
Thank you!
As per the CODEX documentation:
Function
Description
the_permalink( int|WP_Post $post )
Displays the permalink for the current post.
get_permalink( int|WP_Post $post, bool $leavename = false )
Retrieves the full permalink for the current post or post ID.
The difference is subtile. the_permalink is used to DISPLAY the current post permalink and get_permalink is used to RETRIEVE it.
In Wordpress, functions starting with the_ are a a container for the same get_ version. They the_ version echo`-it out and sanitize it.
You never echo something that is already echo-ed out.
First time here and hoping someone can help me. Apologies if I've done anything wrong with regards to posting this question here...
I've created a slide show (using PHP) based on 8 images loaded from an SQL database (PHPMyAdmin)
I want to be able to click on any one image to open a new page which will then show a larger version of the same.
I've scoured the internet and various other forums but struggling to find any help.
Please let me know if you require any further information prior to providing an answer. Any help will be hugely appreciated.
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<a href="http://stu10.lccwebtest.co.uk/getimage.php">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</div>
My suggestion would be to end the anchor tag after the image (so the image is part of the link), set it's target attribute to _blank (so it opens in a new page), and finally pass some reference to getimage.php (so it can load the larger image). For example:
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<a href="http://stu10.lccwebtest.co.uk/getimage.php?id=<?php echo $product["ID"];?>" target="_blank">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</a>
</div>
I've made an assumption on what your primary key is for "products", replace "ID" in my example above with the correct primary key.
Based on further discussion we established that getimage.php has no other function other than to show the larger image. So in that case how about doing away with it and adding the larger image url directly to the anchor as in the below:
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<?php $largerImageUrl = $product["Product_Image"]; //replace the code here with your actual larger image url for this slide ?>
<a href="<?php echo $largerImageUrl;?>" target="_blank">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</a>
</div>
That reduces a lot of extra work. The only times you'd need a script in the middle would be if the larger image location was a secret or you wanted to somehow record the number of times it was viewed or you wanted to display some other html around the image. In other words, if it had some other function.
Ok so here is the link to the template code for gallery.
https://github.com/JoomShaper/Helix-Joomla/blob/master/helixPlugin/shortcodes/gallery.php
However when I insert images on my database (not in Php), the image shows up but I am unable to click that image and be directed to the images page, which I have hyperlinked on my database (Joomla). I will have multiple images where I will need to add this click function to.
I have been trying to figure this out forever. I am new to Php and coding, so forgive my ignorant use of word choices from the above paragraphs.
(I've noticed in the past when speaking to coders it is frustrating for them to code the jargon from a someone who doesn't know the language ha!) Thanks!
Sorry, I know this is not an answer probably, but I cannot comment yet. I have been looking at your code for a little while, and I noticed some things I wanted to ask you about. First:
<?php foreach ($galleryArray as $key=>$item) { ?>
<li style="width:<?php echo round(100/$columns); ?>%" class="<?php echo str_replace(',', ' ', $item['tag']) ?>">
<a class="img-polaroid" data-toggle="modal" href="<?php echo ($modal=='yes')? '#modal-' . $key . '':'#' ?>">
<?php
echo '<img alt=" " src="' . $item['src'] . '" />';
?>
<?php if($item['content'] !='') { ?>
<div>
<div>
<?php echo do_shortcode($item['content']); ?>
</div>
</div>
<?php } ?>
</a>
</li>
You begin your a and li inside the foreach loop, but you finish them outside of it. Considering that the a is your link, and your link is not working, I thought this could be part of your issue.
Also, I noticed that when you link to the modal, you use the same variables from the loop, but the variables were defined inside the loop and would not carry over on clicking the link that was generated. It seems to me that you would need to define a property value with the variable you need from each one, so that you can use JS to do something along the lines of "onClick" grab "this.property.value" so that you could have that information in the modal.
I only thought this was of note because the modal you are opening with the link is named by one of these variables. Unless you are creating a separate modal for each one inside the foreach loop, the name you are linking to does not exist. Sorry if this is confusing.
I'm trying to use the is_page conditional tag to create a slider that displays different sets of images depending on the page.
Below I've created an example of the code I'm using. All I'm getting back is a blank page and I'm really not sure why. Everything I've looked at on Google tells me my Syntax is correct (At least from what I can tell).
I am using the is_page tag before the loop in WordPress so that shouldn't effect it as far as I'm aware. Please correct me if I'm wrong.
I tried placing <?php wp_reset_query(); ?> just before the loop too, but it had no effect.
Any ideas what I might be doing wrong?
EXAMPLE:
<div id="container">
<?php if (is_page('123') || is_page('356')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image1.jpg" width="650" />
<?php } ?>
<?php if (is_page('123') || is_page('356') || is_page('638') || is_page('1199')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image2.jpg" width="650" />
<?php } ?>
</div>
PROBLEM SOLVED:
<?php
// THIS GIVES US SOME OPTIONS FOR STYLING THE ADMIN AREA
function custom_design() {
echo '<style type="text/css">
#wphead{background:#592222}
#footer{background:#592222}
#footer-upgrade{background:#592222}
textarea {white-space:nowrap;overflow:scroll;}
</style>';
}
add_action('admin_head', 'custom_design');
?>
It seems this piece of code in my functions.php was causing the error. The CSS "whitespace:nowrap" was breaking any new template pages I was making. Totally bizarre. Never seen CSS do that before, at least not to that extent.
Sorry for wasting your time guys, thank you for the help. At least I know I wasn't going crazy now.
:)
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?