I am setting up a wordpress website and want to alter a plugin to work with another so that when a news link is clicked it will open in a lightbox using an iframe. I believe the following instances to be where the link is made.
<a href="<?php echo $link; ?>
I am looking to add the following to the link, at the end.
?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]"
I am unsure of how to combine the two. I am hoping by doing so that I correctly located and understood what needed to be changed. If you want to see the full PHP file I have added it to http://pastebin.com/sFqSb1Ha
While I wouldn't mind someone telling me the answer, I would be happy to just be pointed in the right direction for the knowledge I need to study to accomplish this.
Try this:
<a href="<?php echo $link . '?iframe=true&width=100%&height=100%"' . 'rel="prettyPhoto[iframes]"'; ?>
I can see that there are a lot of $link echos in the code you provided. To apply that attrubute for all, you may set $link before, like:
$link = $link . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
(Note that " at the end is missing, because it's already provided in href="").
But if you want to use it for a single link, try
<a href="<?php echo $link; ?>?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" ...
There is just a little problem. If in $link there are parameters in URL, it will fail, because any other param must start with &, and we have ?iframe there. So it's good to check, whetever the ? sign occurs in $link or not.
if (strpos($link, '?') > 0)
$link = $link . '&iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
else
$link = $link . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
Try this
<a href="<?php echo $link ."?iframe=true&width=100%&height=100%\" ". " rel=\"prettyPhoto[iframes]\" "; ?>
for echo use " you can use other varible in this
Related
I'm a little lost here, hoping that someone can help. I'm using the Meta Box plugin for WordPress, and I'm trying to create a process for the user to select an option from a predefined list, and then assign a URL to that option as a link. Im trying to define the URL in a variable, and then call it in a function, but I'm still a little green on PHP syntax. this is my code now:
<?php
$article_url= rwmb_meta('orion_2016_article_url', 'type=URL');
if (rwmb_meta('orion_2016_article_source') != '') {
echo '<a href= ("$article_url") target=blank>';
echo rwmb_meta('orion_2016_article_source');
echo '</a>';} ?> on <?php the_date(); ?>
Since the options are already predefined, it seems like assigning a random URL to one of the options should be pretty simple. Hopefully this makes sense!
You need to to place variables you wish to echo inside double quotes or simply concatenate strings using . as in my example. Note that I didn't check the plugin's specific syntax, only general PHP syntax.
<?php
$article_url= rwmb_meta( 'orion_2016_article_url', 'type=URL' );
if (rwmb_meta('orion_2016_article_source') != '') {
echo '' . rwmb_meta( 'orion_2016_article_source' ); . '';
} ?> on <?php the_date(); ?>
The code below is generating a result like this: http://localhost/my_website/ contact-us
$base_url="http://localhost/my_website/";
echo $link= "$base_url contact-us ";
But I am trying to get a result like this : http://localhost/my_website/contact-us
I have also tried the following code
$base_url="http://localhost/my_website/";
echo $link= "$base_url.contact-us ";
but the result is like this http://localhost/my_website/.contact-us
Could you please show me how to solve this problem?
Edit
I am very sorry, I did't clearly mention the exact problem I am facing here. I thought the above example would help my case. Actually I am trying to create a link that I will send at users email address.
My code
$base_url="http://localhost/my_website/";
$random_hash="1";
echo $link="
<a href='$base_url account/confirm_registration/$random_hash' target='_blank'>$base_url account/confirm_registration/$random_hash</a>";
But it is generating like this
http://localhost/my_website/ account/confirm_registration/1
echo $link = $base_url."contact-us";
$base_url="http://localhost/my_website/";
echo $link= $base_url."contact-us";
You just need to split it
Tested and works:
$base_url="http://localhost/my_website/";
echo $link=$base_url."contact-us";
$base_url="http://localhost/my_website/";
$link=$base_url."contact-us";
echo $link;
You need to learn about basic string concatenation: http://php.net/manual/en/language.operators.string.php
Try this:
$base_url = "http://localhost/my_website/";
$random_hash = "1";
$url_page = "account/confirm_registration/$random_hash";
$url = $base_url . $url_page;
$link = "<a href='$url'>$url</a>";
echo $link;
Hopefully this is simple to solve. I have a few elements which pull in form data previously entered into the database, which are added to the post as custom fields. I extract this using a php query as such:
<a href="<?php echo get_post_meta($post->ID, 'societywebsite', true); ?>" target="_blank" >Website</a>
Obviously, this appears in the Loop (content.php) and will get added to any appropriate post. Sometimes, however, there won't be any data because a user chose not to enter a website into the 'societywebsite' field on a form. When this happens, there's no need for a link to 'Website' to be there, because it wouldn't go anywhere useful.
What I'd like to know is how to have an If clause that checks if the data exists and then shows the link only if it does. I don't mind javascript, but the cleaner and less 'hacky' the solution, the better, as content.php will run multiple times for search results.
Thanks so much for any help or advice you can provide.
Another way to do this, more according to the Wordpress Codex is the following...
$societywebsite = get_post_meta($post->ID, 'societywebsite', true);
if ($societywebsite != '') {
echo '<a href="' . $societywebsite . '" target="_blank" >Website</a>';
}
You can add an 'else' at the end of this for debugging purposes.
Assuming that field is a string for a url, you could do something like this.
if (strlen(get_post_meta($post->id, 'societywebsite', true)) < 1) {
echo '<a href="' . get_post_meta($post->ID, 'societywebsite', true) . '" target="_blank" >Website</a>';
}
That will very simply check if that field has a string that is more than 1 characters. If it is more than 1 characters, it will display the link. If not...it won't do anything.
This is the code I am working with:
echo '' . $post_type->labels->singular_name . '' .$markup;
It currently links correctly but shows the entire http string before the link.
Example: http://www.blah.com/blah/blahPortfolio. When it should be just "Portfolio".
Fresh eyes on this would be so helpful.
There are two errors that I can see:
<?php bloginfo('template_directory'); ?> If you are using echo it means <?php tag is already open so use only bloginfo('template_directory')
There are two closing tag for a tag (i.e. />) You use only one (i.e. >)
So the code will be like this:
echo '' . $post_type->labels->singular_name . '';
Try this code chunk and let me know --
echo '' . $post_type->labels->singular_name . '';
I have been using the following to add a dynamic link on a page I am writing, it works ok and appears how it should on the page but I cant help but think that I am going a bit backwards with the way its written as it looks messy. What is the correct way to write it, as if I put it all in one line it doesn't work ?..
echo '<a href="./customer-files/';
echo $customerID;
echo '/';
echo $filename->getFilename();
echo '">';
echo $filename->getFilename();
echo '</a>';
Try with
echo "{$filename->getFilename()}";
Here there is the documentation with a lot of examples of how to concatenate output.
I'd approach it like this:
$safe_customer_id = htmlspecialchars(urlencode($customerID));
$safe_filename = htmlspecialchars(urlencode($filename->getFilename()));
$safe_label = htmlspecialchars($filename->getFilename());
echo "$safe_label";
I would go with this:
$fn = $filename->getFilename();
$link = $customerID . '/' . $fn;
echo ''.$fn.'';
If you're using a template layer, it is even better to break out into PHP only when you need to:
<a href="./customer-files/<?php
echo $customerID . '/' . $filename->getFilename()
?>">
<?php echo $filename->getFilename() ?>
</a>
This way, your IDE will correctly highlight your HTML as well as your PHP. I've also ensured that all PHP is in single-line blobs, which is the best approach for templates (lengthy statements should be banished to a controller/script).
Concatenation is your friend. Use a . to combine multiple string expression into one.
echo ''.$filename->getFilename()/'';
Even better way would be
$filename = $filename -> getFilename(); //cache the filename
echo "<a href='/$customerId/$filename'>$filename</a>";
// ^ On this echo NOTICE that variables can be DIRECTLY placed inside Double qoutes.