Skip to:
Content
Pages
Categories
Search
Top
Bottom

PHP Help (Compressing code)

  • @kickerman360

    Member

    Hi,

    I not that good at php so I was wondering if some wouldn’t mind shortening this bit of code:

    <?php  echo('<img src="/forums/avatars/' . $current_user->user_login . '.jpg" />'); ?>
    <?php echo('<img src="/forums/avatars/' . $current_user->user_login . '.png" />'); ?>
    <?php echo('<img src="/forums/avatars/' . $current_user->user_login . '.gif" />'); ?>
    <?php echo('<img src="/forums/avatars/' . $current_user->user_login . '.jpeg" />'); ?>

    Basically it is supposed to go through every file extension allowed by the avatar plugin and display the image with the actual extension, there can be only one.

    It is used to display Avatars in WordPress by the way without loading bbPress.

    Any help would be great!

Viewing 4 replies - 1 through 4 (of 4 total)
  • @finalwebsites

    Participant

    You don’t need to use all the php tags and how do you test if the image exists?

    @nightgunner5

    Member

    <?php echo('<img src="/forums/avatars/' . basename( current( glob( BB_PATH . 'avatars/' . $current_user->user_login . '.*' ) ) ) . '" />'); ?> (Untested, but it should work.)

    @kickerman360

    Member

    NightGunner5: I’ll test that when I get a chance, thanks!

    FinalWebsites: The plugin calls the image a certain name. If the user is “admin” the admin’s avatar will be “avatar.jpg” but could also be “avatar.gif” etc. This code hopefully will reduce the code.

    Thanks again!

    @finalwebsites

    Participant

    @Nightgunner5,

    so you can use a wildcard here?

    glob( BB_PATH . 'avatars/' . $current_user->user_login . '.*' )

    after 6 years of php programming I found this function, thanks :)

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar