0

I've nearly finished a new WordPress theme, my first. There is a bit of custom code and unfortunately I am fairly new to PHP.

http://www.designated.net.au/testbed/wordpress/

As you can see there is a "spotlight" area for sticky posts. But there are no sticky posts at the moment and every post is displaying in there. When a post is made sticky it will display in there on its own.

What I would like to do is make it so the entire spotlight area doesn't display if there are no sticky posts. I have no idea where to start.

5
  • 2
    Can you provide the php code behind this site? Commented Sep 25, 2012 at 12:37
  • Post some code so we may help you.. You can use pastie.org or jsfiddle.net Commented Sep 25, 2012 at 12:39
  • Thanks guys. This is the code I want to hide: pastie.org/4797229 Commented Sep 25, 2012 at 12:44
  • offtopic but your remix is awesome ;) Commented Sep 25, 2012 at 12:46
  • Thank you very muchly! If you like that check out my sets. Commented Sep 25, 2012 at 12:51

1 Answer 1

1

Well, you can use the visible: hidden CSS property of the div to hide it, or display:none. You just need to check if there is any sticky post to display.

<?php
    query_posts(array('post__in'=>get_option('sticky_posts')));
    // $nbrStickyPost = something 
    $stickyPost = ""

    if($nbrStickyPost === 0) {
        $stickyPost = " style=\"display:none;\""
    }

    echo "<div id=\"spotlight-feature\"", $stickyPost, ">";
?>

<div id="spotlight-feature-top">
<!-- [...] -->

<?php while (have_posts()) : the_post(); ?>
<!-- [...] -->

This code will add the display:none CSS property to your div if the nbrStickyPost var is 0. I would need to see some of the query_posts() and have_posts() functions to really determine nbrStickyPost.

Sign up to request clarification or add additional context in comments.

14 Comments

Oh inside the echo, I see. I'll give it a shot.
I think I implemented it correctly but stickyPost = "" gives me a parse error.
Well, as I said, it depends on your actual PHP code, the vars are of course different for you but it's just an example of what you could add to do what you want. You need to add the display:none property to your div when there are no post. There should be a var somewhere in the code with the count. That's the one you have to look for, and you also have to find the right div to hide. Just post your code if you want some more help there.
Oh ok. I have to find the var.
Mistake on my part, it's $stickyPost instead of stickyPost. Haven't been doing PHP since a while. Just edited my original post.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.