Jump to content


Echo Within Echo

echo php

  • Please log in to reply
1 reply to this topic

#1 RyanPym

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 08 December 2012 - 04:29 PM


I am new to the forum, and am hoping you can help, I know a little about PHP, but not enough to solve an issue I have with a wordpress site I am currently working on. I am currently working with a plugin that shows posts by a specific user.

At present, you can put the plugin into the theme pages by using <?php echo do_shortcode('[latestbyauthor author="username" show="3"]'); ?> This requires you to manually input the authors username.

I am trying to automate this, setting the user name based on the users profile you are viewing - here is the user profile page for reference:http://www.copymusic...OPYmusicscout2/

Now I am familiar with how to pull the relevant users name, as I have used the following code to correctly display the "view uploads by xxxxx" link. I have been using the following: <?php echo $user->screenname; ?>.
I therefore tried using <?php echo do_shortcode('[latestbyauthor author="<?php echo $user->screenname; ?>" show="3"]'); ?> which didn't work.

I read something online which suggested the 2nd echo wasn't required so I tried <?php echo do_shortcode('[latestbyauthor author=" $user->screenname" show="3"]'); ?> which again didn't work.

I am therefore a little stuck . . At the moment it is just displaying the last few posts onto the site, I have tried manually inputting the relevant user name and it does work, but obviously shows the same posts regardless of user profile!
I am pretty familiar with some PHP so can take simple instructions, unfortunately I am a bit stuck at this time!

Any suggestions will be greatly appreciated, if you need any more detail, please let me know!

Many thanks

#2 scootstah

  • Moderators
  • Advanced Member
  • 3,864 posts
  • LocationUSA

Posted 08 December 2012 - 04:33 PM

You're close. Check out the manual page for strings; http://php.net/manua...ypes.string.php

Since you're using double quotes you can either enclose the variable with curly brackets, or you can concatenate.

<?php echo do_shortcode('[latestbyauthor author=" ($user->screenname)" show="3"]'); ?>

<?php echo do_shortcode('[latestbyauthor author=" " . $user->screenname . "" show="3"]'); ?>

EDIT: Oops, I guess you are actually using single quotes. So you'd have to concatenate then:

<?php echo do_shortcode('[latestbyauthor author=" ' . $user->screenname . '" show="3"]'); ?>

Edited by scootstah, 08 December 2012 - 04:34 PM.

while(!$succeed = try());

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users