[wp-hackers] Hijack "The Loop"?

Lorin Rivers lrivers at gmail.com
Fri Apr 27 17:59:28 GMT 2007


OK, that makes sense. I've never used that SQL construction before, thanks.

On 4/27/07, Otto <otto at ottodestruct.com> wrote:
> I think you're missing the point. You're not "retaining access" to
> anything. You build and actually run the query a second time.
>
> This gives you the first person in your list of people:
> SELECT user_id, last_name, maiden, first_name, nickname, suffix FROM
> $wpdb->alumni WHERE class_year = '$class_year' ORDER BY $order LIMIT
> 0,1
>
> This gives you the second:
> SELECT user_id, last_name, maiden, first_name, nickname, suffix FROM
> $wpdb->alumni WHERE class_year = '$class_year' ORDER BY $order LIMIT
> 1,1
>
> This gives you the third:
> SELECT user_id, last_name, maiden, first_name, nickname, suffix FROM
> $wpdb->alumni WHERE class_year = '$class_year' ORDER BY $order LIMIT
> 2,1
>
> You're not "retaining" anything. When they hit the next button, you
> actually run the query again for the next person that you want. You
> just up the number in the limit to get the next user.
>
>
>
> On 4/26/07, Lorin Rivers <lrivers at gmail.com> wrote:
> > OK, that's good to know. Can you tell me how to retain/access a query so
> > that I can apply LIMIT to it and get the next item?
> >
> > On 4/26/07, Otto <otto at ottodestruct.com> wrote:
> > >
> > > The thing I think you're missing is an understanding of the MySql LIMIT
> > > clause.
> > >
> > > SELECT * FROM your_table LIMIT 5, 10
> > >
> > > That will select 10 entries from "your_table", skipping the first 5 of
> > > them. So you will get entries 6,7,8,9,10,11,12,13,14, and 15,
> > > basically.
> > >
> > > This is how Wordpress does the post loops, more or less. Each "page"
> > > has X entries. Page 1 starts with entry 0. Page 2 starts with entry
> > > number X. Page 3 starts with entry 2X. And so on.
> > >
> > > So your "profile" page could be the same as your normal query (more or
> > > less), but with a LIMIT of X,1, where X is the number of that person
> > > in the result set (0-indexed). To get the next guy, you run the same
> > > query with X+1.
> > >
> > > I cannot tell you specifically how to apply this to your application,
> > > but the gist of it is that Wordpress does not really retain the query
> > > from page to page. It builds the same query that it did before, but
> > > with new variables for the LIMIT clause.
> > >
> > >
> > >
> > > On 4/25/07, Lorin Rivers <lrivers at gmail.com> wrote:
> > > > Paul is my hero, he got me to this point.
> > > >
> > > > Take a look at my follow-up, though.
> > > >
> > > > On 4/25/07, Paul Menard <codehooligans at codehooligans.com> wrote:
> > > > > No. You really don't want to do that. I can answer this because well
> > > > > I know what you are working on.
> > > > >
> > > > > For example on the custom search result page. If the your secret
> > > > > 'alum_search' parameter is present you are dropping into your custom
> > > > > SQL query which hits you alumni table and searched for matching
> > > > > records. the result of this query is a standard mysql array (see my
> > > > > example below). If you don't have the secret 'alum_search parameter
> > > > > then you default to using the WP Loop to display any Post/Page items.
> > > > > You really can't hijack the loop since your table columns don't
> > > > > really apply to WP functions like the_title(), the_content(), etc.
> > > > >
> > > > > For your custom query you just need to make your own loop and display
> > > > > the row information from your alumni contact table Something like the
> > > > > following. This is straight from the PHP MySQL manual.
> > > > >
> > > > > $query = "SELECT..."; // your custom quuery
> > > > > $result = mysql_query($query);
> > > > > while ($row = mysql_fetch_assoc($result))
> > > > > {
> > > > >      echo $row['firstname'];
> > > > >      echo $row['lastname'];
> > > > >      echo $row['address'];
> > > > >      echo $row['age'];
> > > > > }
> > > > > mysql_free_result($result);
> > > > >
> > > > > P-
> > > > >
> > > > >
> > > > > On Apr 25, 2007, at 1:22 PM, Lorin Rivers wrote:
> > > > >
> > > > > > Here's what I'm doing--I've got a custom table and some page
> > > > > > template-fu to display data that is not "posts". WP is so
> > > post-centric
> > > > > > that a lot of stuff doesn't work if the content is not in "the
> > > loop".
> > > > > >
> > > > > > Is it possible to make my custom PHP ACT like The Loop? And if so,
> > > > > > how?
> > > > > >
> > > > > > Thanks!
> > > > > > _______________________________________________
> > > > > > wp-hackers mailing list
> > > > > > wp-hackers at lists.automattic.com
> > > > > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > > > > >
> > > > >
> > > > > _______________________________________________
> > > > > wp-hackers mailing list
> > > > > wp-hackers at lists.automattic.com
> > > > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > > > >
> > > > _______________________________________________
> > > > wp-hackers mailing list
> > > > wp-hackers at lists.automattic.com
> > > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > > >
> > > _______________________________________________
> > > wp-hackers mailing list
> > > wp-hackers at lists.automattic.com
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list