Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End can any wordpress legend help me with a simple if statement please?

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #30034
    silverlulu
    Participant

    Hi guys!

    ok this is probably simple for someone that understands the loop.

    on one page i am showing 5 posts, but when you click “older entries” it doesn’t display the next 5 posts. it displays the same posts again… so i am doing something wrong.

    this is the page that i am talking about… http://star-signings.com/category/deals/

    disclaimer: i am using category.php to control both the deals and the news section (i don’t know if i should have seperate pages for each?) – if someone could explain the pros and cons of having loops for different pages in the category.php then that would be absolutley amazing…

    anyway this is the loop i am using at the moment and i think i need something added to it, so that it works properly when you click “older entries”

    
    query_posts('category_name=deals&posts_per_page=5');
    };
    ?>

    obviously this is saying, if it’s the deals page, show 5 posts, but how do i get it to work properly?

    below is the whole code for category.php just incase it helps! =

    THANK YOU SO MUCH FOR HELPING ME! I WOULD LOVE YOU IF YOU COULD HELP ME WITH THIS!!!










    Star Management Signings












    Latest News



    Our Deals


    Here is a selection of deals that Star Management have been involved in, either representing the club or on behalf of the player:



    My beautiful posts baby!


    players

    This is some generic text to describe all other category pages,
    I could be left blank










    Posts Tagged ‘




    Archive for




    Archive for




    Archive for




    Author Archive




    Blog Archives








    query_posts('category_name=deals&posts_per_page=5');
    };
    ?>
    query_posts('category_name=news&posts_per_page=10');
    };
    ?>







    >






    ">



    ">



    My beautiful posts baby!


    players

    This is some generic text to describe all other category pages,
    I could be left blank
















    Nothing found













    rss













    #81283
    Hayley
    Member

    I had this problem on my site. Now – I’m very new to all this, so I don’t guarantee anything :-)
    From my understanding, query_posts does not work with pagination (older entries link, etc.) You have to include the paged argument. Here’s where I found out about it:
    http://codex.wordpress.org/Function_Reference/query_posts
    Try this code for your query:



    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'deals',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    ?>

    #81285
    Hayley
    Member

    Oops, I forgot the conditional statement for your ‘deals’ category:



    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'deals',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    }
    ?>

    I think this might work :-)

    #81240
    silverlulu
    Participant

    Hi Hayley!

    wow thanks soo much for your help. I used it and it works! i am having issues using it in the news section for some reason, but it works in the deals part!

    thanks very much for everything!

    i have used it like this… the first loop works a treat, but the second loop doesn’t! i don’t know why, but maybe someone else could help?!

    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'deals',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    }
    ?>
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'news',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    }
    ?>
    #81232
    Hayley
    Member

    Hmm…I’ve never done 2 like that. Wait, maybe it needs to be an if/elseif statement. That would make more sense. Taking a stab at it here:



    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'deals',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    }
    elseif (is_category('news')) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'category_name' => 'news',
    'post_per_page' => 5,
    'paged'=>$paged,
    );
    query_posts($args);
    }
    ?>

    #80532
    Hayley
    Member

    thanks @betzster – that’s much better. I really need to learn PHP :-)

    #94909

    Hi.

    There is something very important about the loop and using the query_posts function that you are missing. It is the reason why your first attempt at having two loops did not work. After each loop, you must reset the query. It is important to do, even when you are only running query_posts once on a page.

    How do you do it? Just add a line like this at the end of the loop after the endwhile at a minimum and if you have navigation at the bottom of the page that takes the user to more pages of stuff in the same loop, then be sure to put this line _after_ that as well.

    Hope this helps. I just figured this out the other day and it has enabled me to do all kinds of fancy things now.

    Cheers!

    #96822
    dhrumin
    Member
    
    
    };
    ?>

    I learned this much from this post.

    I have created posts for different lightboxs.

    For lightbox post i have catagory called ‘lightbox’ When i click on link.

    [lightbox href=”http://localhost/?p=229″ iframe=”true” width=”700″ height=”460″]Open [/lightbox]

    It opens whole post with header and sidebar and everything.

    I was wondering if we can hide header, sidebar, footer everything except that post data. That would be great…

    Please let me know if its possible and how can i achive this.

    Thanks a ton.

    * I am using twenty eleven theme.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Back End’ is closed to new topics and replies.