How to turn a text called out by PHP into a link? - php

I'm currently using Wordpress and I have website listings that has link names as titles (eg. www.test.com, www.test2.com)
With this php code, it calls out the name of the website link:
<h3 class="list"><a class="h1" href="<?php the_permalink(); ?>"><?php the_title(); ?></h3>
Now that website has a "readmore" button and a "visit website" button. I'd like to turn the "visit website" button into a external link using PHP.
For example, the website listing is called "www.test.com". I'd like to turn the "visit website button" into an external link that will make it go to "www.test.com".
Here is my html code for the "visit website button":
<div id="visit">
Visit website
</div>
I hope someone can help.
Thanks!

I suppose you could do something like this instead
<h3 class="list"><a class="h1" href="http://<?php the_title(); ?>">Visit Website</h3>
If the_title is a valid URL starting with www (not http://), then it'll work. If they already have http:// in the title, remove that part.

Whenever you click a link you are visiting the url specified in href attribute.
For example to create a link, to go to google.com I would do this
Go to Google
So in you case you replace # with your link
<div id="visit">
Visit website
</div>

code it in php:All i can think of is this code:
<?php echo "<a href='http://www.test.com'>visit site</a>" ?>
I guess you are confused by
<?php the_permalink(); ?>
the_permalink(); calls get_permalink(); which finally provides the link.You can see its source code in wp-includes/link-template.php.

Related

Wordpress get the current permalink/canonical URL?

I need to insert the my page permalink on the end of a Facebook share URL.
Any help is much appreciated. E.g. <a href="facebook.com/share.php/'<?php the_permalink(); ?>'"> doesn't work.
The format of the Facebook sharing link is:
https://www.facebook.com/share.php?u={{LINK}}
So in your example it'd be:
<a href="https://www.facebook.com/share.php?u=<?php the_permalink(); ?>">

Facebook Comments Shortcode with Post ID

I am using a wordpress template for Music Promotion and trying to connect facebook comments plugin via "https://developers.facebook.com/docs/plugins/comments/" ... I understood all the steps and successfully connected by the shortcode with browser.. Here is the single album page where the comment plugin shows after the listed songs... "http://shanmp3.net/?download=sai-aung-htee-kham&lang=en"
HERE IS THE SHORTCODE I AM USING FOR FACEBOOK COMMENTS IN MY SINGLE-CONTENT-PAGE.PHP
<div class="fb-comments" data-href="https://www.shanmp3.net" data-numposts="5"></div>
ACTUAL PROBLEM
When I comment on any post it not working as unique and showing the same comment on all the post as I am using "PHP" Single Content Page so I am unable to write a proper code as
<?php echo urlencode(get_permalink($post->id)); ?>
which work unique for each Post.
I appreciate if you provide me the correct PHP Code as per Post ID which work unique for each post.
Cheers...
Alright I have just sorted out myself and its very simple as you just need to replace :
<div class="fb-comments" data-href="mydomain.com" data-numposts="5"></div>
mydomain.com with PHP the_permalink as the following:
<div class="fb-comments" data-href="<?php the_permalink() ?>" data-numposts="5"></div>

Facebook share only certain div

So I have the following code for facebook share.
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" class="post_share_facebook" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=220,width=600');return false;">
<i class="icon-facebook"></i>
</a>
Right now, when the share button is clicked, the whole snapshot of the page is shown on the share window.
On a php file where this share button is located, I have a specific div which I want to show on the Facebook share window instead of the whole snapshot of the page.
Does anyone know how I can do this?
Thanks!
Not sure if its possible that way, you can try <?php the_permalink(); ?>#your_div_id
Another alternate would be using open graph

"Read more" button bug in Wordpress custom theme

I'm new to php coding and I need to fix a bug in my friend's website. Here is the page with the bug http://www.corectura.ro/category/in-presa/ (it's in Romanian, but it doesn't matter). "Citeste mai multe..." is the "Read more..." link and it doesn't work. It just opens the same page (this one: http://www.corectura.ro/category/in-presa/) in a new tab, instead of opening the link/post in order to read more just as the "read more..." button says. The site is on Wordpress platform and has a custom theme.
I've looked into the editor in all the php files for the section where the "read more" is mentioned. I only found it in archive.php and styles.css.
In the styles sheet the only code i found is this one (regarding to the read more link)
.r_more{ display:block; text-align:right; }
And in the archive.php the code below:
<li>
<div class="post_thumbnail"><?php the_post_thumbnail('thumbnail'); ?></div>
<div class="post_content"><h3><?php the_title(); ?></h3>
<div class="date_post"><?php echo ucfirst(get_the_date('F Y')); ?></div>
<?php the_excerpt();
echo 'Citeşte mai multe...';
?>
</div>
</li>
Is there something wrong with this code? Is the syntax correct? Why does it open the same page in a new tab instead of opening the page with the content that's needed to be shown after clicking "Citeste mai multe..." ("Read more...")?
Please help. Thank you.
You are using echo, so you need to change the_permalink() to get_permalink() (which returns the permalink):
echo 'Citeşte mai multe...';
Try this instead:
<?php the_excerpt(); ?>
Citeşte mai multe...

i open link from custom fields but it open along with original site

i make custom field in wordpress and insert link there like www.google.com i get this custom field like this
<?php $episode=get_post_meta($post->ID, "download_link", true);
?>
<a class="more-linkk" href="<?php echo $episode ;?>" target="_blank"></a>
now it opens in url like this http://dramapk.net/movie/www.google.com i want it just open google.com so kindly guide me
<a class="more-linkk" href="<?php echo "http://".$episode ;?>" target="_blank"></a>
If your link doesn't start with the protocol (http:// or https://) the browser puts the domain name before, so your link is invalid.

Categories