WordPress.org

Ready to get started?Download WordPress

Forums

"Taglines" for pages and posts? (2 posts)

  1. onechrisjones
    Member
    Posted 6 years ago #

    I want to display a custom tagline instead of my page title at the top of my static pages. Is there a way to use custom fields for that?
    Ideally, I would like to be able to (when editing a page/post) specify a title, then a tagline, and then the body of the post/page. Is there a plugin for that? is there a hack or something I could do?
    I guess that would be considered metadata- Is the ability to do that already in WP (just hidden somewhere)?
    My PHP knowledge is less than my wordpress knowledge... All I know of PHP is what i have learned building/editing themes.
    I have too many hours logged editing themes though. I built too many to count.
    I would appreciate any help/direction I could get towards hacks or plugins... i feel like i have scoured the internet with google, but to no avail.
    I am having a bit of trouble grasping the custom fields thing too, so if that is the way i would do this, please advise me in a direction I could go to learn that functionaity.

  2. Jeremy Clarke
    Member
    Posted 6 years ago #

    Hey dude, totally doable.

    Best place to start: http://codex.wordpress.org/Using_Custom_Fields

    Lots to think about in there (and worth it, if you're making a lot of sites with wp, meta hacking is invaluable)

    For your particular need the tag you most likely want to use is get_post_meta($post->ID, $key) (described in the wiki article above). the $post->ID tells it to get the meta values (typed into the meta field thing on the post/page editing screen) for the current post (inside 'the loop') and you can just type in the $key that you want (which is what you called the meta value on the edit screen).

    SO: if you always add a meta field called "tagline" to your pages/posts you can add the following in your loop:

    <?php
    if (get_post_meta($post->ID,'tagline')) {
    echo get_post_meta($post->ID,'tagline');
    }
    ?>

    The first line checks to see if the tagline is there, and the second one prints it out if it is. FUN! You can also add some lines inside the if {} to have formatting and stuff, to avoid the formatting showing if you ever forget to add a tagline.

    After all that, you might also want to look into plugins related to meta, especially http://rhymedcode.net/projects/custom-field-gui/ , which lets you set meta fields to always show up in the editor.

Topic Closed

This topic has been closed to new replies.

About this Topic