WordPress.org

Ready to get started?Download WordPress

Forums

How to automatically add random content on blank spaces (8 posts)

  1. androskee
    Member
    Posted 2 years ago #

    Hi, I did a search online, but I couldn't find the answer I was looking for it.
    How do I add something, like text, or any other content, if on single post page a post is short, which leaves blank space below, as my sidebars are at certain lenght. I know how to fill blank spaces manualy, but is there any way it can be done automatically by adding php code or something. let's say for example have code if post characters are more than 100 display something else.
    http://www.androskee.com/driving/wrong-way i posted my website's link where you can see what i mean...

  2. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    Set a min-height on the style of the post content section that matches your sidebar layout.

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    you can check the post's length for instance with:

    <?php $character_length = strlen(strip_tags(get_the_content())); ?>

    http://php.net/manual/en/function.strlen.php

    then use that infomation in a conditional statement either in a filter function or after the 'content' div in your single.php.

    where is the text suppose to come from?
    any random text?
    related to the post?
    length correlated to the length of the post?
    ...

  4. androskee
    Member
    Posted 2 years ago #

    to Seacoast Web Design:
    Member, that it won't work, still will have a blank space in post box, but thanks anyway:)

    to alchymyth The Sweeper:
    I haven't decided what text yet. It could be any random text or related posts excerpt, it's basicly to fill the blank space where it's applicable.
    Could you please post an example of the code?
    Let's say if the post is less than 100 characters or words, then I would like to display extra content to fill the blank space, how it can be done?

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    general example for added code after the div with 'the_content()':

    <?php if( strlen(strip_tags(get_the_content())) <= 100 ) { ?>
    <span class="filler-text">
    filler text
    </span>
    <?php } ?>
  6. androskee
    Member
    Posted 2 years ago #

    Thankyou very much, I will try this :)

  7. androskee
    Member
    Posted 2 years ago #

    it worked. Your help has been very appreciated. :) Thankyou again for it!

  8. androskee
    Member
    Posted 2 years ago #

    can i use the code above for, if content height is more than, let's say 600px then display filler text?

Topic Closed

This topic has been closed to new replies.

About this Topic