So I'm using the custom pinterest button builder and it spits out and anchor that looks like this:
<a href="//gb.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" data-pin-config="none">
The url is composed of a few parameters, which are url, media and description.
I want to replace each parameter with my own, using php in wordpress.
I'd like something along the lines of this:
<a href="//gb.pinterest.com/pin/create/button/?url=<?php echo $url; ?>&media=<?php echo $url; ?>&description=<?php the_title(); ?>" data-pin-do="buttonPin" data-pin-config="none">
If you look at pinterests example the url and description are encoded to replace spaces and special characters with %20 or other % type replacements.
So, how do I encode a url like:
http://lart.co.uk/wordpress/wp-content/uploads/2014/03/30d5466ca31411e3863812695239df89_8.jpg
And text like:
This is a description
so pinterest will accept it?
Use urlencode(). Pay attention to the parameters in the_title():
<a href="//gb.pinterest.com/pin/create/button/?url=<?php echo urlencode($url); ?>&media=<?php echo urlencode($url); ?>&description=<?php echo urlencode(the_title(null,null,false)); ?>" data-pin-do="buttonPin" data-pin-config="none">
Related
I have a URL that looks like:
example.com/profile.php?id=1
I want to dynamically generate the URL by taking username from the form input in the database's id field. Like :
example.com/profile.php?id=username
This link give errors.If I use below link than it works
example.com/profile.php?id="username"
But , I am facing problem in anchor tag.My Code :
<a href="contributor-profile.php?id=<?PHP echo "$data['id']";?>">
<h4 class="contributor-name">
<?PHP echo $data ['name'];?>
</h4>
</a>
I have also used urlencode fuction but it is not working.
<a href="profile.php?id=<?PHP echo urlencode($data['id']);?>">
<h4>
<?PHP echo $data ['name'];?>
</h4>
</a>
I am building a wordpress site with galleries in it and want to add a 'Back to Gallery' link in my single-attachment.php that will send the user back one directory.
For example, if the image is at www.site.com/galleries/gallery1/image1/ I would want the link to send it back to www.site.com/galleries/gallery1/.
Any suggestions would be appreciated.
You can either explode current URL,and remove last term from the URL and give it as link for Back to Gallery.
<?php $url = explode('/', 'www.site.com/galleries/gallery1/image1/');
array_pop($url);
$back=implode('/', $url);
?>
<a href="<?php echo $back; ?>" >Back to Gallery</a>
Or you can use $_SERVER['HTTP_REFERER'] for getting the previous URL.
<a href="<?php echo $_SERVER['HTTP_REFERER']; ?>" >Back to Gallery</a>
also by using javascript you can implement this in easy way :
<a href="javascript:history.go(-1)" >Back to Gallery</a>
I am using a wordpress theme that has a custom post type called "link" which simply produces a post where the title links to an outside link you specify. It also includes some text in the body of the post. I would like to also be able to display an image. Right now it is not showing the image.
Here is the code:
elseif ( has_post_format( 'link' )) {
if(get_post_meta($post->ID, '_format_link_url', true)!=''){
$link = get_post_meta($post->ID, '_format_link_url', true);
}else{
$link = '';
}
?>
<h2 class="entry-title">
<a href="<?php echo $link; ?>" target="_blank" title="Follow this link">
<?php the_title(); ?>
</a>
</h2>
<p>
Is there anything I can add to make it display an image as well as text?
Thanks!
I can't see anywhere on this example where you are using an tag to insert an image. The img tag has two required attributes, src and alt. Src is the path to your image, whereas alt is the alternate text for the image. So:
<img src="images/myImage.png" alt="This Is My Image"/>
Hope that helps!
I was wondering if someone could tell me the correct way to link to another page from within a view.
Is there a function for this or is it just the usual about
I assume you are meaning "internally" within your application.
you can create your own <a> tag and insert a URL in the href like this
Link
OR you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
and that will generate
Link
For the additional commented question
I would use my first example
so...
<img src="<?php echo base_url() ?>img/path/file.jpg" />
for images (and other assets) I wouldn't put the file path within the PHP, I would just echo the base_url() and then add the path normally.
The best way is to use the following code:
Link
you can also use PHP short tag to make it shorter. here's an example
<a href="<?= site_url('controller/function'); ?>Contacts</a>
or use the built in anchor function of CI.
Best and easiest way is to use anchor tag in CodeIgniter like eg.
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
Refer https://www.codeigniter.com/user_guide/helpers/url_helper.html for details
This will surely work.
you can also use this code
//test" class="btn btn-primary pull-right">
<a href="<?php echo site_url('controller/function'); ?>Compose</a>
<a href="<?php echo site_url('controller/function'); ?>Inbox</a>
<a href="<?php echo site_url('controller/function'); ?>Outbox</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
I'm now doing it this way:
<a title="<?php echo $title; ?>">...
But it will brreak when " is included in $title.
Not that it's "the final solution", but obviously you need to escape any literal string that isn't mean to contain HTML. In this case:
<a title="<?php echo htmlspecialchars($title); ?>">
You should run that through htmlspecialchars first to make sure your HTML won't break.
You should translate special characters into HTML entities first, easily done with htmlentities().
<a title="<?php echo htmlentities($title); ?>">