Support » Plugins and Hacks » [Resolved] Trying to make tiny PHP script for displaying Blog Name

[Resolved] Trying to make tiny PHP script for displaying Blog Name

  • 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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    No, no, get_bloginfo() is what you want. 😉

    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?

    @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…

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

    This issue is resolved.

    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.


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Trying to make tiny PHP script for displaying Blog Name’ is closed to new replies.
Skip to toolbar