• Hello

    In a first time, sorry for my poor english… and I’m not sure to post this topic on the correct forums (sorry by advance in case of error)

    I would be interested in adding two actions in the wordpress loop,
    in addition to loop_start and loop_end.

    My suggestion is to add “loop_before_each” and “loop_after_each“,
    called respectively before and after each element of the loop.

    In order to do this, we only need to add this line at the end of the_post() function :

    do_action('loop_before_each', &$post);

    and at the beginning of have_post() function :

    do_action('loop_after_each');

    Of course, the same thing can be do for the comment loop…

    Thanks for reading !

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter adiguba

    (@adiguba)

    One mistake : the function have_post() can be called many time by a theme so it cannot déclare ‘loop_after_each’.

    But the action ‘loop_before_each’ on the_post() can be very useful for me…

    Bye

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    This is a problematic idea for a lot of reasons, but the main one is that a theme may have several Loops, not all of which you would want to hook onto.

    Better to put your tags to call your code directly into the theme itself, where you want your code to be called.

    Thread Starter adiguba

    (@adiguba)

    Yes : it can be possible to do this on a theme, but I want to make an independant plugin, which would operate on all themes.

    In fact i’m using “WordPress MU”, and I want to make a plugin that would allow a blog to show posts from several other blogs.

    Even if this is not quite complete, I’am already do the job on the SQL query, by adding some filters (like ‘posts_query’ and ‘the_posts’).

    So my WordPress loop return to me differents posts from differents blogs, and each $post data includes an additional element “blog_ID”, allowing me to identify the blog.

    My problem is that I must call the switch_to_blog() with this “blog_ID”, before each post on the loop, in order to print correct data (permalink…) I’m doing this by adding a filter ‘loop_before_each’ at the end of the_post().

    But I think it could be interresting ta add the action directly on WordPress for futures versions (if I have this need, perhaps some others peoples can have the same).

    Thanks for replying,

    Bye

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[RFE] Add action for loop’ is closed to new replies.