• Resolved 2nic

    (@2nic)


    hello,

    for some mysterious reason, i can’t use the query_posts() at all on my new blog. i was used to use it, and quite fan of it.

    could it be because for the first time i used sandbox (created a theme based on sandbox?)

    this is what i tried in archive.php :

    <?php query_posts($query_string.'&order=ASC'); ?>
    <?php if (have_posts()) : ?>

    as it didnot work out, i tried with :

    <? $order='ASC';
    $myquery = new WP_Query("order=$order");
    ?>
    <?php if($myquery->have_posts()) : ?>

    which is actually still written in tht page, but not working at all : posts are still displayed in descending order.

    i created a template that i’m using within a page, and it works nice. the problem is with this code is i’m obliged to have all posts listed on a single page, because if i limit the number of posts (using LIMIT at the end of the query), i can’t navigate through pages ( can’t use the defautl function as <?php posts_nav_link(); ?>for instance.)

    would anybody have an idea?

    thanks in advance,

    <?php
    /*
    Template Name: Reverse
    */
    ?>
    <?php get_header() ?>
    
    <div id="container" style="width:650px;">
      <div id="content" >
        <?php //query_posts('orderby=date&order=ASC'); ?>
        <?php
    
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts
        WHERE wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date ASC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
     ?>
        <div id="nav-above" class="navigation">
          <?php posts_nav_link(); ?>
        </div>
        <?php if ($pageposts): ?>
        <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
        <div  id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
          <div class="entry-date" style="margin-bottom:5px"> <?php printf(__('%1$s  %2$s', 'sandbox'), the_date('', '<b>', '</b><br /><br />', false), get_the_time()) ?>
            <?php edit_post_link(__('Edit', 'sandbox') ); ?>
          </div>
          <div style="margin-top:0; padding-top:0;"  class="entry-content">
            <?php the_content(''.__('Read More <span class="meta-nav">&raquo;</span>', 'sandbox').''); ?>
            <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'sandbox') . '&after=</div>') ?>
          </div>
          <div class="entry-meta"> </div>
        </div>
        <!-- .post -->
        <?php //comments_template() ?>
        <?php endforeach; ?>
        <?php endif; ?>

    kind regards, veronique

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter 2nic

    (@2nic)

    so, here i am again

    what is exactyle the query_posts() function doing, is what i don’t know.

    it is written :

    function &query_posts($query) {
    	unset($GLOBALS['wp_query']);
    	$GLOBALS['wp_query'] =& new WP_Query();
    	return $GLOBALS['wp_query']->query($query);
    }

    i die several things

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query_string=$query_string."&paged=$page&order=ASC";
    echo "$query_string <br />";
    query_posts($query_string); ?>

    the echoed query_string gives this :
    “paged=4&year=2008&monthnum=03&paged=4&order=ASC “

    which is quite what i am looking for, but, no result on the page

    Thread Starter 2nic

    (@2nic)

    so i tried this :

    <?
    echo ” avant $request “;
    $request = str_replace (“DESC”, “ASC”, $request);
    echo “après $request”;
    ?>

    and… i finally had my posts in a reverse order – bien s?r, c’est triché…

    but, of course the navigation through the pages does not work.

    so, i’m not so sure i found my solution.

    kind regards,

    any help welcome !

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I don’t understand the problem. This code will work:

    <?php query_posts($query_string.'&order=ASC'); ?>
    <?php if (have_posts()) : ?>

    What is it giving you instead?

    Thread Starter 2nic

    (@2nic)

    so, i did this :

    <?
    echo  " //avant $request ";
    echo "page $page";
    $request = str_replace ("DESC", "ASC", $request);
    if (ereg ("5, 5", $request)) $request =  str_replace ("5, 5", "5, 10", $request);
    if (ereg ("10, 5", $request)) $request =  str_replace ("10, 5", "10, 15", $request);
    if (ereg ("15, 10", $request)) $request =  str_replace ("15, 10", "15, 20", $request);
    echo "après $request";
    ?>

    well, it works… but

    result here :

    https://www.historyze.org/veronique-m/2008/03

    Thread Starter 2nic

    (@2nic)

    hello Otto42,
    millions of thanks, and thanks again

    why is it that it now works and what would the difference be between what i tried (well one of the things i tried :

    <?php get_header() ?>
    <?php query_posts($query_string.'&order=ASC'); ?>
    
    	<div id="container">
    		<div id="content">
    
    		<?php if (have_posts()) : ?>

    and the code I copied from you (and pasted) :

    <?php query_posts($query_string.'&order=ASC'); ?>
    <?php if (have_posts()) : ?>

    is not really clear to me.

    but again : thanks !

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Well, there is no difference. That was sort of my point, I copy and pasted your original code. That code should have worked in the first place. Maybe you made a typo?

    Thread Starter 2nic

    (@2nic)

    you’re right, there’s no difference.

    the difference is, i understand it now, that i thought i had disabled one by one each plugin, to check whether…

    but, i’ve just realised that i might had thougt i had deactivated “WP-Sticky 1.10” (the new 2.5 panel (?) sometimes deactivates ou ractivates something else than what you wished).

    the great culprit (?) (coupable) is the WP-Sticky 1.10
    sorry for my english

    but thanks again for your attention

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘query_posts(); not working at all’ is closed to new replies.