Generating a list of games from posts

Discussion in 'PHP' started by emforce, Dec 12, 2009.

  1. #1
    Hi guys I am trying to figure out how to generate a list of all the games on my website and plant them on one of my pages. I want to list them alphabetically and just have the title and the link to the posts.

    Thanks Guys!
     
    emforce, Dec 12, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you have a list of games? how are they set on your site? This is very vague
     
    JAY6390, Dec 12, 2009 IP
  3. emforce

    emforce Member

    Messages:
    308
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #3
    I have posts on the games which lead to other articles on that game or similar. So I put them in a category of "Games" that way whenever someone opens the games tab they see the latest etc.. but I want to create a page that will list all the games ever put up on 1 page for instance

    <a href="#">Title of Game 1 in Category Games</a>
    <a href="#">Title of Game 2 in Category Games</a>
    <a href="#">Title of Game 3 in Category Games</a>
    <a href="#">Title of Game 4 in Category Games</a>
     
    emforce, Dec 12, 2009 IP
  4. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #4
    I'm guessing that GamerCity.co.uk is the site in question? That's Wordpress, so you're looking at something like this:

    <?php $query = new WP_Query('category_name=games&showposts=-1&orderby=title&order=ASC);
    while ($query->have_posts()) : $query->the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <br/>
    <?php endwhile; ?>
    PHP:
    If you need that code to execute on a Wordpress page (one you create via the admin panel), you should try http://wordpress.org/extend/plugins/exec-php/ , which'll let you run PHP code in your pages.
     
    Last edited: Dec 12, 2009
    Wogan, Dec 12, 2009 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    JAY6390, Dec 12, 2009 IP
  6. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Aha, now that IS clever... And all you'll need to do is drop that PHP into functions.php for the theme...
     
    Wogan, Dec 12, 2009 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, those shortcodes are pretty cool
     
    JAY6390, Dec 12, 2009 IP
  8. emforce

    emforce Member

    Messages:
    308
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #8
    Ok so I installed the plugin you mentioned. And pasted the code into my page, as well as changing the category to its name. But it doesn't seem to work as no titles are coming up at all.
     
    emforce, Dec 12, 2009 IP
  9. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Try changing showposts= to 5, see what happens?
     
    Wogan, Dec 12, 2009 IP
  10. emforce

    emforce Member

    Messages:
    308
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #10
    Nah I tried that but it didn't work, checked again and still no.
     
    emforce, Dec 12, 2009 IP
  11. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #11
    You have error reporting turned off. There's a missing ' at the end of the first line:

    ...title&order=ASC');
    Code (markup):
    Just tested the fixed version on my blog and it seems to work.
     
    Wogan, Dec 12, 2009 IP
  12. emforce

    emforce Member

    Messages:
    308
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #12
    Your a genius! Thanks a lot!

    Btw is there any good sites that you can recommend that will teach me php?
     
    emforce, Dec 12, 2009 IP
  13. emforce

    emforce Member

    Messages:
    308
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #13
    Thank you JAY6390 as well I didn't see your reply there but it is much appreciated!
     
    emforce, Dec 12, 2009 IP