WordPress.org

Ready to get started?Download WordPress

Forums

Ideas for WP_Post and template tag improvements (1 post)

  1. Manny Fleurmond
    Member
    Posted 1 year ago #

    This idea is a simple one: encapsulating the post-based template tags (the_ID, the_title, the_content, etc) and make them methods of the WP_Post object.

    Basically what this does is allow developers and theme makers to take advantage of the template tags in custom loops without actually messing around with the main loop or the global $post and removing the need to reset post data. Since the template tags use post data to begin, it makes sense for the core logic to be in the WP_Post class. The global template tags can just call the methods of the global $post object in a main loop.

    For example if you have a custom query:

    $query = new WP_Query();

    Instead of calling the_post to load the global variables, you could do:

    while( $query->have_posts ) : $query->next_post();
        $query->post->the_title();
        $query->post->the_content();
    endwhile;

    Basically, you call the template tags directly from the post instead of messing with the main loop variables.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Manny Fleurmond
  • This topic is not resolved
  • WordPress version: 3.5.1