WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP help needed - echo HMTL based on Author ID (8 posts)

  1. TrishaM
    Member
    Posted 4 years ago #

    I need some help troubleshooting a snippet of PHP code (I'm not a trained coder, but trying to learn).....

    I'm trying to echo some HTML based on the author of a post being viewed, so I am using this statement, but it's not working correctly:
    ~
    <?php
    $exp = the_author_meta('ID');
    if($exp = 4) {
    echo '(the html I want echoed goes here)';
    } elseif($exp = 3) {
    echo '(some different html I want echoed goes here)';
    }
    ?>~

    I also tried it with the ID number in single quotes like this ($exp = '4')

    It only ever echoes the first html, regardless of what the author ID is, even if it is neither of the two I have shown (I have more than a dozen authors, but just want this HTML code echoed if it is one of these two)

    Can anyone spot what I'm doing wrong? Thanks for any help!

  2. MichaelH
    Member
    Posted 4 years ago #

  3. TrishaM
    Member
    Posted 4 years ago #

    Hi MichaelH

    Thanks for that - I see what I did wrong with the operator, and i even corrected the problem with the quotes for the echo statement but even though it looks like it should be right, it's still not working - all that gets echoed is the authors ID number, not the HTML

    Here is what I have

    $exp == the_author_meta('ID');
    if ($exp==4) {
        echo "<span class=\"myclass\">(the rest of the html with quotes escaped where they appear)</span>";
    } elseif ($exp==3) {
    echo "<span class=\"myotherclass\">(the other html with quotes escaped where they appear)</span>";
    }

    Any thoughts?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    The the_author_meta Template Tag displays the desired meta data for a user.
    [...]
    Use get_the_author_meta() if you need to return (not display) the information.

    http://codex.wordpress.org/Template_Tags/the_author_meta

  5. TrishaM
    Member
    Posted 4 years ago #

    Thanks esmi - that works! As always you are a gift to the rest of us!

    That also helped solve (part) of another problem I have that I posted here:

    http://wordpress.org/support/topic/305089?replies=3#post-1198593

    I'll update that post with this advance and what I'm still having trouble with.

    Thanks again! :) :)

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    I'd have posted the get_the_author_meta Codex url too but it seems to just redirect to the page for the_author_meta. :-(

  7. TrishaM
    Member
    Posted 4 years ago #

    I figured that out too after clicking on that link on the_author_meta age a few times :) so it would be nice if that page was created, but I gathered after reading it a few times and your clues that it works exactly LIKE the_author_meta except that it RETURNS the result, not displays it.....eventually the lightbulb went off in my head and I got it.

    thanks so much!

  8. redkite
    Member
    Posted 4 years ago #

    This is close to what I need to do too, I've modified it to this, but it's not yet working:

    <?php
    	$company == get_the_author_meta('company');
    	$test == the_author_meta('industry');
    	if ($test=='Web/Interactive') {
    	echo $company;
    	}
    ?>

    Can someone point out what's wrong here?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.