WordPress.org

Ready to get started?Download WordPress

Forums

Trying to retrieve all categories of all posts that will be displayed (1 post)

  1. Floppie
    Member
    Posted 1 year ago #

    Hello,

    Long time reader, first time poster ;)

    So I have this problem I'm trying to solve. My end goal is to have Adsense ads above my content area and to the right of my content area, so I'm using my theme's (Mystique) header code option and a sidebar text widget to display them. The caveat is that I have a handful of posts whose content will violate Google's content terms.

    Having already spoken with somebody at Google to verify that I can still use Adsense on the site as long as it's not displayed on the same page as the violating content, I figured the easiest solution would be to have a category/tag to mark posts as being not-Adsense-safe. Then, in the code that displays the ads, just have it perform a check (in PHP land I assume) to see if any posts of that category are present on the current page and, if so, skip displaying the ads (or pick something non-Adsense if I ever decide to use other ad networkd).

    Cool, seems like a simple enough solution. I'm currently trying to use get_the_category() and just loop through the results, checking each one as I go. The problem I'm having is that get_the_category() only seems to return categories for the current post unless a post ID is passed.

    So my question is, is there any way (within PHP) to retrieve an array of all posts that are queued to be displayed by the current browser request? If not, is it possible to retrieve this clientside via Javascript?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic