ThemeShaper Forums » Thematic

[closed]

Target Non-Single Posts and Insert Div

(6 posts)
  • Started 2 years ago by JE2KB
  • Latest reply from JE2KB
  • This topic is resolved
  1. Hi Guys,

    Big fan of thematic, and have a small problem.

    I am trying to use functions.php to insert a new div element around my posts. I have it working BUT only want to target posts that aren't on a single page.

    This is what I have so far:

    if (!is_single()) {
    function new_blog_top() {
    echo "<div class='page_blog'>";
    }
    add_action('thematic_abovepost','new_blog_top');

    function new_blog_bottom() {
    echo "</div>";
    }
    add_action('thematic_belowpost','new_blog_bottom');
    }
    else {
    break;
    }

    I have also tried is_singular but it applies it to both posts on my blog page, and posts on their own single page. What am I doing wrong?

    Posted 2 years ago #
  2. have you tried is_archive() ?

    Posted 2 years ago #
  3. Hey Helga,

    Just tried that too, had my hopes up, but it still doesn't work. With is_archive() it does not display the new Div for any of the posts, single or otherwise.

    Any other suggestions?

    Posted 2 years ago #
  4. Warning: You can only use conditional query tags after the init action hook in WordPress. For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function.

    From the codex, you are putting it outside of the function, put it within, this should work.

    function new_blog_top() {
    	if (!is_single()) {
    		echo "<div class='page_blog'>";
    	}
    }
    add_action('thematic_abovepost','new_blog_top');
    
    function new_blog_bottom() {
    	if (!is_single()) {
    		echo "</div>";
    	}
    }
    add_action('thematic_belowpost','new_blog_bottom');
    Posted 2 years ago #
  5. oh crap- i didn't even notice that. <facepalm>

    Posted 2 years ago #
  6. Haha champion! Thanks very much, both of you :)

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.