The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. androskee
    Posted 4 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 Web Design
    Posted 4 years ago #

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

  3. Michael
    Forum Moderator
    Posted 4 years ago #

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

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


    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
    Posted 4 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. Michael
    Forum Moderator
    Posted 4 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
    <?php } ?>
  6. androskee
    Posted 4 years ago #

    Thankyou very much, I will try this :)

  7. androskee
    Posted 4 years ago #

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

  8. androskee
    Posted 4 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