• Hi,
    I was wondering if anyone knows how I’d set up a post title similar to the below link. I don’t see a direct way within WP. Is there a plugin that would do it?:

    http://cityfile.com/dailyfile/4516

    Right above the linked title there’s a little descriptive title “Media”.
    Sometimes the little subtitle might appear below the title. How would I add those little nonlinked descriptive titles either above or below the main linked title?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I assume you know that cityfile.com is not a WordPress site…

    2 possible approaches:
    1) Create Media as a category or tag. Apply the category or tag Media to posts. Display a category page with all Media category posts. Display the name of the category (Media) above the first post title. This approach requires displaying the posts on category or tag pages

    2) Add a custom field to posts, containing the word(s) you want to display above (or below) the post title. Change your template code to look up whether a custom field with the correct Key value exists on that post. If it does, print it, above or below the post title.

    Thread Starter wsam

    (@wsam)

    Thanks for responding stvwlf.

    It sounds like #2 above is more what I’m interested in. I’m not a coding expert though. Is there any sort of documentation that you can point to that would be a roadmap to making the code changes that you mention? I’m not afraid to dig in and make changes, but just have no clue where to start.

    Thanks.

    Inside the loop, in your single.php file, you’ll want to add something like the following:

    <?php $subtitle = get_post_meta($post->ID, 'secondary_title', $single = true); ?>

    Then, wherever you want the subtitle to appear in the post, you would need to add

    <?php if($subtitle !=='') { ?>
    				<h2><?php echo get_post_meta($post->ID, "secondary_title", true); ?></h2>
    			<?php } ?>

    Where the h2 tags are your subtitle containers (you might want to give it a dedicated class so you can style it accordingly).

    In your post (actually writing the post in the editor) you would go down to custom fields and, if you were using the terms in the above code, you would add a custom field with a name of secondary_title and then whatever that title is in the value field. After you’ve done that once, you’ll be able to select the secondary_title name from the drop-down list in custom fields.

    Hope that helps

    John

    The following…

    <?php if($subtitle !=='') { ?>

    Need not use !=='' … (not equal to nothing) …

    <?php if($subtitle) { ?>

    Will be sufficient… which is basically the same thing..

    I imagine you could also use…

    <?php if(!empty($subtitle)) { ?>

    You might find the second easier to read… perhaps not, either will work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do you set up a post title with a secondary title?’ is closed to new replies.