简体   繁体   中英

php a href link don't work

How to make it properly? The variable is not working in href link

<?php
$currentlang = get_bloginfo('language');
$pl = "http://example.com/wp-content/uploads/2014/09/CV.pdf";
$en = "http://example.com/wp-content/uploads/2014/09/Curriculum-Vitae-English.pdf";
?>
<?php if ($currentlang=='pl-PL') { ?>
<a href=$pl class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } else { ?>
 <a href=$en class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } ?> 

Correct Your code,

<?php
$currentlang = get_bloginfo('language');
$pl = "http://example.com/wp-content/uploads/2014/09/CV.pdf";
$en = "http://example.com/wp-content/uploads/2014/09/Curriculum-Vitae-English.pdf";
?>
<?php if ($currentlang=='pl-PL') { ?>
<a href="<?php echo $pl; ?>" class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } else { ?>
 <a href="<?php echo $en; ?>" class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } ?> 

Do this:

<?php
$currentlang = get_bloginfo('language');
$pl = "http://example.com/wp-content/uploads/2014/09/CV.pdf";
$en = "http://example.com/wp-content/uploads/2014/09/Curriculum-Vitae-English.pdf";
?>
<?php if ($currentlang=='pl-PL') { ?>
<a href='<?php echo $pl; ?>' class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } else { ?>
 <a href='<?php echo $en;?>' class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } ?> 

Add quotation marks and add <?php tag in the variable.

You are not calling your variable the proper way. Use this:

<a href="<?php echo $pl; ?>" .... > text </a>

You need to call it inside and use echo for it, including quotations marks to wrap the href with.

<?php if ($currentlang=='pl-PL') { ?>
<a href="<?php _e( $pl, 'site5framework' ); ?>" class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } else { ?>
 <a href="<?php _e( $en, 'site5framework' ); ?>" class="vecard" title="<?php _e( 'CV', 'site5framework' ); ?>">CV</a>
<?php } ?> 

According to your coding standards!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM