WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress Inside Joke Prank (7 posts)

  1. sanchit
    Member
    Posted 6 years ago #

    I want some piece of code that will see if the person who posted a post is author_ID #3 and I want it to display Ricky Martin instead of his name. I was just looking around various things but I can't figure out how to make the_author() not return anything. Maybe if someone can point that out I'll see how I can make it return but not echo the name.

    <?php if (the_author()=="User Name" && $user_ID!=3 && $user_level > 0 && ($user_ID=1 || $user_ID=7 || $user_ID=5 || $user_ID=2 || $user_ID= 4)){ echo "<a href=".get_bloginfo('template_directory')."/images/ricky_martin.jpg>Ricky Martin</a>"; } else { the_author_posts_link(); }?>

    This code seemed to work but it only works for the first post. The_author has no parameters.. I just found that the_author('',false) somewhere and tried it and it worked.

    Do you guys get what I am trying to do here? Help is most appreciated. Making users 2,4,5 and 7 be the only people to see Ricky Martin and it only says Ricky Martin if someone is logged on AND of course uID#3 doesn't know or suspect anything.

  2. sanchit
    Member
    Posted 6 years ago #

    Can someone tell me where the_author and other function are written so that I can solve this on my own? Which file in which folder?

    Thanks.

  3. Dgold
    Member
    Posted 6 years ago #

    Dang, I don't know the answer, but that is pretty funny stuff right there. Making some users see "Ricky Martin" every time your buddy posts, lolz.

  4. sanchit
    Member
    Posted 6 years ago #

    well... no thanks to everyone here but I found the_author() function with the depreciated functions in wp-includes/author-template.php I am going to mess around it over there.

    I still don't know why when I put in that code it only works for the first post by that author on a page.. :\

  5. sanchit
    Member
    Posted 6 years ago #

    <?php
    global $user_level; global $user_ID; get_currentuserinfo();
    //echo $user_ID;
    if ($user_ID==2 || $user_ID==7 || $user_ID==4 || $user_ID==5)
    {
    if (get_the_author_login()=="PersonsLoginName")
    { echo "<a>Ricky Martin</a>"; }
    else { the_author_posts_link();  }
    }
    else { the_author_posts_link();  }
    ?>

    I think this works fine.. the problem with the earlier code might have been the fact that in the $user_ID=watever it should be ==

    Anyways, enjoy.

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    the_author isn't deprecated. And all you have to do is this, in your theme, instead of "the_author()":

    $author=get_the_author();
    if ($author=="Username") echo "Ricky Martin";
    else echo $author;

    Another way, which would work even with the_author or author_posts_link or anything else is to use a filter on the_author. You'd add this to your theme's functions.php file:

    function joke_author($author) {
    if ($author == 'Username') return 'Ricky Martin';
    else return $author;
    }
    add_filter('the_author','joke_author');

    Adding the user_id stuff should be obvious, you're just going to add an "&& ($user_ID=1 || $user_ID=2)" stuff to the if statements.

  7. sanchit
    Member
    Posted 6 years ago #

    I realized that I needed a get_the function cause they don't echo but they just return the values. Once I got to see the actual functions for my own in the author-template.php file everything became clear as to how I could use everything.

    You're making the same mistake as me! $user_ID==1 :P

    Thanks for the input. Problem is solved though. :)

Topic Closed

This topic has been closed to new replies.

About this Topic