 |
|
|
06-20-2010, 01:28 PM
|
how to add code in echo?
|
Posts: 173
Name: Abdullah Saleem
|
Hi,
How could I add the following code :
PHP Code:
<br />
<a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php"><?php $toplinks6 = get_option('stylewp_toplinks6'); echo $toplinks6; ?></a> | <a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php?action=register"><?php $toplinks4 = get_option('stylewp_toplinks4'); echo $toplinks4; ?></a>
after
PHP Code:
} else { echo 'Welcome, Guest!';
Actual Script is here, what I want
PHP Code:
<?php if ( is_user_logged_in() ) { global $current_user; get_currentuserinfo();
echo 'Welcome, <b>' . $current_user->display_name . "</b>\n";
} else { echo 'Welcome, Guest!'; };
?>
If user logged in then display Logout else, Login & Register, which is above in the code.
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
Last edited by asmalik12; 06-20-2010 at 01:30 PM..
|
|
|
|
06-20-2010, 02:23 PM
|
Re: how to add code in echo?
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Is this what you mean:
PHP Code:
<?php
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo 'Welcome, <b>' . $current_user->display_name . "</b>\n";
} else {
echo 'Welcome, Guest!';
?>
<br />
<a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php"><?php $toplinks6 = get_option('stylewp_toplinks6'); echo $toplinks6; ?></a> | <a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php?action=register"><?php $toplinks4 = get_option('stylewp_toplinks4'); echo $toplinks4; ?></a>
<?php
}
?>
|
|
|
|
06-21-2010, 03:20 AM
|
Re: how to add code in echo?
|
Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
|
Rather than opening and closing PHP tags all over the place:
PHP Code:
<?php if ( is_user_logged_in() ) { global $current_user; get_currentuserinfo();
echo 'Welcome, <b>' . $current_user->display_name . "</b>\n";
} else { echo 'Welcome, Guest!';
$toplinks6 = get_option('stylewp_toplinks6'); $toplinks4 = get_option('stylewp_toplinks4');
echo '<br /><a class="topbarlink" href="' . get_settings('home') . '/wp-login.php">' . $toplinks6 . '</a> | <a class="topbarlink" href="' . get_settings('home') . '/wp-login.php?action=register">' . $toplinks4 . '</a> ';
}
?>
__________________
Please login or register to view this content. Registration is FREE
Learn professional skills from professional people, from $6.50 a month.
Last edited by Phunk Rabbit; 06-21-2010 at 03:22 AM..
|
|
|
|
06-21-2010, 03:23 AM
|
Re: how to add code in echo?
|
Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
|
Just looking over the code and suddenly realised, how come you are mixing OOP and procedural code?
__________________
Please login or register to view this content. Registration is FREE
Learn professional skills from professional people, from $6.50 a month.
|
|
|
|
06-21-2010, 09:04 PM
|
Re: how to add code in echo?
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by Phunk Rabbit
Just looking over the code and suddenly realised, how come you are mixing OOP and procedural code?
|
What exactly is wrong with the code? It is common in PHP to use objects in code that would otherwise be purely procedural. The object he uses, $current_user, is a global in wordpress. It doesn't seem to me like he is using it inappropriately.
|
|
|
|
06-22-2010, 03:51 AM
|
Re: how to add code in echo?
|
Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
|
I was under the (obvously wrong lol) impression that when using OOP code you should make an effort to have the whole site running in OOP rather than mixing objects and procedual code.
Bereing in mind i never attually said there was anything wrong with the code but instead was looking to see if there was a particular reason he was using both methods 
__________________
Please login or register to view this content. Registration is FREE
Learn professional skills from professional people, from $6.50 a month.
|
|
|
|
06-22-2010, 01:45 PM
|
Re: how to add code in echo?
|
Posts: 144
Name: Nick Mallare
Location: Olathe, KS
|
Quote:
Originally Posted by Phunk Rabbit
I was under the (obvously wrong lol) impression that when using OOP code you should make an effort to have the whole site running in OOP rather than mixing objects and procedual code.
Bereing in mind i never attually said there was anything wrong with the code but instead was looking to see if there was a particular reason he was using both methods 
|
A general rule of thumb to remember is that OOP code can have a lot of overhead. It should be used only when needed and only if applicable. Do not get me wrong, I love a good site that utilizes the power of PHP OOP; however, it does have its time, place and purpose.
Nick
|
|
|
|
06-23-2010, 02:55 AM
|
Re: how to add code in echo?
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by nmallare
A general rule of thumb to remember is that OOP code can have a lot of overhead. It should be used only when needed and only if applicable.
|
Where are you getting that from? Unless I'm mistaken the overhead (if any) of using objects is negligible. I can't think of any circumstance (in PHP) where I would advise against using objects due to performance.
|
|
|
|
06-23-2010, 05:39 AM
|
Re: how to add code in echo?
|
Posts: 173
Name: Abdullah Saleem
|
I have done it. Someone culd now tell me how to add javascript in echo?
Javascript Code :
Code:
<a href="#" onclick="javascript: if(sIB.style.display=='none'){sIB.style.display='block';}else {sIB.style.display='none';}">Sign In</a>
<p>More Content</p>
<div id="sIB" style="display:none;margin-top:-50px;position:absolute;background:#888888;padding:20px;border:10px solid #666666;color:#ffffff;">Sign In Box Contents Here</div>
<p>Content Content Content</p><p>Hoooray for content</p>
I want to display this box in Sign in link :
PHP Code:
$toplinks6 = get_option('stylewp_toplinks6');
$toplinks4 = get_option('stylewp_toplinks4');
echo '<br /><a class="topbarlink" href="' . get_settings('home') . '/wp-login.php">' . $toplinks6 . '</a> | <a class="topbarlink" href="' . get_settings('home') . '/wp-login.php?action=register">' . $toplinks4 . '</a> ';
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|
|
|
|
06-23-2010, 07:03 AM
|
Re: how to add code in echo?
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
HTML and javascript are client side code. There is no special way to "add javascript in echo"; all output is the same to PHP. If you want something to be included in the output received by the user then either echo it as a string, or close the PHP tags and include the code just as you would normal html or javascript code.
PHP Code:
<?php
//php code here
?>
<a href="#" onclick="javascript: if(sIB.style.display=='none'){sIB.style.display='block';}else {sIB.style.display='none';}">Sign In</a>
<p>More Content</p>
<div id="sIB" style="display:none;margin-top:-50px;position:absolute;background:#888888;padding:20px;border:10px solid #666666;color:#ffffff;">Sign In Box Contents Here</div>
<p>Content Content Content</p><p>Hoooray for content</p>
<?php
//more php here
?>
|
|
|
|
06-23-2010, 09:46 AM
|
Re: how to add code in echo?
|
Posts: 144
Name: Nick Mallare
Location: Olathe, KS
|
Quote:
Originally Posted by NullPointer
Where are you getting that from? Unless I'm mistaken the overhead (if any) of using objects is negligible. I can't think of any circumstance (in PHP) where I would advise against using objects due to performance.
|
It is just common sense. If you have a class that has thirty variables and fifteen functions, but you only need to use four of the variables and two of the functions, then you are going to have included a lot of unnecessary code. This is what I was getting at.
That said, as I stated before, I prefer OOP code as it is cleaner. But for optimizing code, procedural can be a very viable solution.
Nick
|
|
|
|
06-23-2010, 08:22 PM
|
Re: how to add code in echo?
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by nmallare
It is just common sense. If you have a class that has thirty variables and fifteen functions, but you only need to use four of the variables and two of the functions, then you are going to have included a lot of unnecessary code. This is what I was getting at.
That said, as I stated before, I prefer OOP code as it is cleaner. But for optimizing code, procedural can be a very viable solution.
|
I think you're optimizing in the wrong places. Even in the circumstance you described the performance difference would be negligible. Even if you had so many instances of such a class that it made a difference, the solution is to rethink your approach, not ditch OOP.
|
|
|
|
06-23-2010, 10:49 PM
|
Re: how to add code in echo?
|
Posts: 144
Name: Nick Mallare
Location: Olathe, KS
|
Quote:
Originally Posted by NullPointer
I think you're optimizing in the wrong places. Even in the circumstance you described the performance difference would be negligible. Even if you had so many instances of such a class that it made a difference, the solution is to rethink your approach, not ditch OOP.
|
Well, we will have to agree to disagree. I am a huge proponent of optimizing at every step, not just some.
Nick
|
|
|
|
08-03-2010, 02:35 AM
|
Re: how to add code in echo?
|
Posts: 13
|
OOP code can be of your used. It is an object-oriented programming code. I prefer this. Let me clarify, I have no grudges against PHP.
|
|
|
|
08-04-2010, 01:04 PM
|
Re: how to add code in echo?
|
Posts: 10
Name: Muhammad Umer Farooq
|
PHP Code:
<?php if ( isset(is_user_logged_in() )) { global $current_user; get_currentuserinfo();
echo 'Welcome, <b>' . $current_user->display_name . "</b>\n";
} else { echo 'Welcome, Guest!'; };
?>
|
|
|
|
|
« Reply to how to add code in echo?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|