WordPress.org

Ready to get started?Download WordPress

Forums

Add title inside the_content (8 posts)

  1. ghaib
    Member
    Posted 3 years ago #

    In WP, the_title is always displayed outside of the the_content, but is it possible to display it inside, so that the title is part of the content, and can be aligned likewise?

    For example, take a look at this site -- notice its titles inside the white box, how the title and the content is aligned to the left, while an images aligned to the right.

    Is this possible in WP?

    Thanks!

  2. JarretC
    Member
    Posted 3 years ago #

    Yes it is possible in WordPress, however that all depends on how the theme is coded of course.

  3. ghaib
    Member
    Posted 3 years ago #

    Well, the theme is coded like any other WP theme.

  4. JarretC
    Member
    Posted 3 years ago #

    That really doesn't help much as there are thousands of themes available nowadays and almost each one is coded slightly differently. Do you have a live website so I can take a look at the code or do you have a theme in mind that you want to use?

  5. alchymyth
    Forum Moderator
    Posted 3 years ago #

    @ghaib
    even in your example link, the title is outside the content; only the image is shown to the right of the title and content, which could be done using the_post_thumbnail() in its own div, for instance.
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail

    unless you can provide the name of the theme that you are planning to use, and/or a link to your site, nobody will be able to help in any substantial way.

    general, there are possible ways to 'push' the title into the content.
    for instance, you could replace:

    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>

    with something like:
    <?php $text = '<h2>' . the_title('','',false) . '</h2>' . get_the_content(); echo apply_filters('the_content', $text); ?>

    i am however not sure how this would help you to achieve a layout as in your example link.

  6. ghaib
    Member
    Posted 3 years ago #

    @alchymyth I applied your code, it seems to be working.

    In essence, what I want is the title (h2) to be included in the same <div> as the content, usually it's:

    <h2>Test title</h2>
    <div class="content">The content</div>

    What I'd like to achieve is something like this:

    <div class="content">
    <h2>Test title</h2>
    The content</div>

    While your code works, what if I want to wrap the title in additional divs, and have it be a link as well?

  7. alchymyth
    Forum Moderator
    Posted 3 years ago #

    what if I want to wrap the title in additional divs, and have it be a link as well?

    should be no problem - simply try it.

  8. ghaib
    Member
    Posted 3 years ago #

    I tried, I'm getting this error:

    syntax error, unexpected T_LNUMBER

    I think it's because I also include the comment code <?php comments_popup_link('0', '1 ', '% '); ?> right after the title (in a div).

    Any ways of fixing this? (I'm not a php wiz :) )

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic