Support » Plugins » Hacks » If single/category

  • Piotr


    What’s wrong with if(is_single(array($settings['excl_post']))==true) { ... }, because it doesn’t work for 2nd, 3rd, etc. value in saved in database in ‘excl_post’? They’re seperated with commas like in example on codex.

    I have this problem with categories too.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Peter Butler


    the array($settings['excl_post']) is just putting the contents of $settings['excl_post'] into a single element in an array. If the contents of $settings['excl_post'] are comma separated post ids, try this:

    $exclude_array = explode(',' $settings['excl_post']);
    if(is_single($exclude_array)){ ...

    You may also need to run a loop over each item in $exclude_array and get the intval() of the item to make sure what you’re holding in the array is an integer, bu tI’m not sure.



    Unfortunely it doesn’t work, but with a loop is great. 😉 Thank you! 🙂

    $exclude_array = explode(",", $settings['excl_post']);
    	for ( $i = 0; $i < count($exclude_array); $i++ ) {
    	if(is_single($exclude_array[$i])==true) {...} }

    But I have one more question. Is it possible to use any conditional tag to check if element is in specific class or id (like div id="sidebar")?

    Peter Butler


    Glad to hear you got it working.

    If I understand your second question properly, no, I dont believe there’s a way to check that. If you explain what you’re trying to do though, maybe we could come up with a different method.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If single/category’ is closed to new replies.