Support » Plugins » Hacks » Add something before content of main loop page

  • Hi there,

    I’m writing a plugin and need to “hook” individual content to the top of the page containing the main post loop (which is not the home page in my case).

    Any hints?


    [ Just an hour and you’re bumping already? Don’t do that, it’s not permitted here. if it’s really urgent then consider hiring someone. ]

Viewing 5 replies - 1 through 5 (of 5 total)
  • So, here I am, “bumping” again: Could you delete this thread? Or make the initial post editable again so that I can add information to my problem instead of having to do this with a reply to my own post?

    As it’s hard to find something about the subject here, I thought opening a thread would help other people as well. But if I’m not able to edit it anymore then: forget about! Just delete it…

    We cannot make your initial post editable again. And the last time you “bumped” this topic (47 minutes ago), you added zero new information.

    OK, here’s one of the things I tried so far:

    I tried to compare the get_option(‘page_for_posts’), where the “individual” posts loop page is saved, with the ID of the current page, using the ‘loop_start’ filter to do this comparison before the loop, where my additional content is supposed to appear.

    if(get_permalink() == get_permalink(get_option('page_for_posts')))...
    The problem is, the when hooked to ‘loop_start’, it’s comparing the permalink of the first post in the loop with the given permalink to for ‘page_for_posts’, which results to false of course, so nothing happens.

    Some more Info: I want to put additional content (a map) to the top of the page for posts and a different one to each category archive page. The second problem is, that is_category() within my plugin doesn’t work. Probably because it’s outside the loop.

    So here’s the question more clearly:
    What solution do you propose to
    1. Add content before the loop on the page for posts?
    2. Add content before the loop on each category archive?


    Moderator bcworkz


    Your more info is what was needed, your initial question was too succinct to really grasp what your are trying to do.

    If you want a single map to always appear at the top of a page that typically has multiple posts, then yes add the map content to the appropriate template before the loop. Then no need to hook anything. You can use single_cat_title() to get the category name from which you determine which map to serve. It actually must be used outside the loop.

    Thanks for your reply, bcworkz. Using single_cat_title() helps a lot.

    As I’m writing a plugin and don’t want to put the content in template files, I think I still have to use a hook/filter – or am I getting things wrong?

    I tried different things to obtain the results mentioned in 1. & 2. in my previous post. ‘loop_start’ seemed to be the best way, but as a content hooked to this position is in the beginning of the loop but already inside of it (true?), I didn’t find a way to figure out if I’m on the page declared in the option ‘page_for_posts’. $post/$page were not working to get the ID of the current page and to compare it with the value set in the option.

    And to hook the extra content (the map in my case) to the top of a category page – I couldn’t figure out how to do this as well. As I said: is_category() didn’t work for me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add something before content of main loop page’ is closed to new replies.