WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Trying to make tiny PHP script for displaying Blog Name (8 posts)

  1. skipcollege
    Member
    Posted 8 years ago #

    I have multiple WP blogs running on my site with 1 set of template files for all of them. In my template file it displays the blog name like this: Blogs ~ Personal Blog. Using the following code...

    <div>Blogs ~ <?php bloginfo('name'); ?></div>

    However on my site I do not refer to one of my WP installations as a blog. I want the template to only display the bloginfo('name') and take off the "Blogs ~ " for the WP one I do not refer to as a blog.

    I was thinking that I could have a PHP script echo just bloginfo('name'); if it is a non-blog WP (Site News) and echo "Blogs ~ bloginfo('name');" if it is considered a blog. I attempted to make a small script to do that with an if statement that compared the bloginfo('name') to the actual name of the only WP install at this time that is not considered a blog "Site News"...


    <?php if (bloginfo('name') == 'Site News')
    { echo (bloginfo('name')); }
    else { echo ("Blogs ~ " . bloginfo('name')); }; ?>

    Here is what this code outputs to the browser...

    "Site NewsSite NewsBlogs ~ "

    It should output "Site News" if it is the site news blog and output "Blogs ~ Blog Name" if it is another blog.

    It seems as though either my php code is bad or the WP bloginfo() function is messing it up. Can you see the problem or do you know of another solution? Thanks!

  2. McShelby
    Member
    Posted 8 years ago #

    Your code ist fine except that bloginfo() echos the desired information. You need a function that returns the desired information instead of it. Just replace 'bloginfo' with 'get_settings' and your code will run a lot smoother.

  3. No, no, get_bloginfo() is what you want. ;)

  4. skipcollege
    Member
    Posted 8 years ago #

    Thanks for the response McShelby...

    I swapped out the bloginfo with get_settings but it didn't work.


    <?php if (get_settings('name') == 'Site News')
    { echo (get_settings('name')); }
    else { echo ("Blogs ~ " . get_settings('name')); }; ?>

    The output was...

    Blogs ~

    So it obviously went to the else part of the statement when it shouldn't have because I was at the Site News blog but the blog name didn't display. I then just tested to see what get_settings('name') would output on its own.

    echo (get_settings('name'));

    It outputted nothing in the browser. Maybe get_settings('name') doesn't work in WP 2.0?

  5. McShelby
    Member
    Posted 8 years ago #

    @Viper007Bond: Ahm yes, that's right. I am always confused which to use when. Ups :)

    @skipcollege: Sorry, see Vipers response from above. He's right...

  6. skipcollege
    Member
    Posted 8 years ago #

    Ah, yes the get_bloginfo is working now! Thank you both Viper007Bond and McShelby.

  7. skipcollege
    Member
    Posted 8 years ago #

    This issue is resolved.

  8. get_bloginfo() is exactly the same as bloginfo(), except it returns rather than echo'ing. Most output functions also have a get_ version.

    get_settings() is used to get a value outta the options table, which of course could be used, but you'd need to use the option name instead which is like blogname or something. I forget.

    http://codex.wordpress.org/Function_Reference/get_settings

Topic Closed

This topic has been closed to new replies.

About this Topic