• Hi,

    I have taken over a wordpress based site which was set up by a web developer (who is no longer available to help me)

    Basically he has PHP code on the front page (a custom template) and this code on the page is pulling the post titles etc to show recent activity.

    The code is:

    <?php query_posts(‘category_name=press&showposts=10&offset=1’); ?>

    See where it says “press” it was pulling the posts labeled as “press” – Now I am being asked to make it a mix or “press” and “blog”

    Can anyone tell me how to alter that line so it pulls both? I tried puting in a comma after press and then adding blog, but it broke everything. I am a bit clueless with PHP after a certain level. Any help would REALLY! help me out.

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter stirlingcreative

    (@stirlingcreative)

    went to that, I only see this:

    query_posts(‘category_name=Staff Home’);

    It doesn’t show me how to grab multiple categories by name? I am really sorry If I sound like a total idiot, I am more comfortable with front end design and back end PHP stuff tends to easily confuse me.

    I even tried putting just a space between the words and it broke the thing, again a comma doesn’t do it, any more advice?

    You need to use category ids if you want to pull from multiple categories. From the page I linked to:

    Multiple Category Handling

    Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6:

    query_posts(array(‘category__and’ => array(2,6)));

    Thread Starter stirlingcreative

    (@stirlingcreative)

    How do I find out the numbers associated with my categories?

    When in admin mode when I hover over “pages” I see the numbers associated with the pages at the end of the URL, however, the part i need to pull from is in the “posts” section and it doesn’t give you a simple number that is associated with the post category.

    I hope this makes sense, if I can find that out then I can put your advice into practice and see if it works for me….

    Thread Starter stirlingcreative

    (@stirlingcreative)

    sorry, figured out the categories part, got those numbers, will now try out your code. will let you know what happened

    Thread Starter stirlingcreative

    (@stirlingcreative)

    OK, sadly for me that made everything break, as I mentioned before I am not exactly a programmer although I am expected to get these things fixed.

    Below is the entire code chunk for what I am trying to do, just incase this sheds more light on a potential problem or makes it easier to see what I am doing wrong

    [Code moderated. Please post code snippets between backticks or use a pastebin for larger blocks of code]

    The top part:
    <?php query_posts(‘category_name=blog&showposts=1’); ?>

    Shows the most recent post, it shows the excerpt from the page with the date etc.

    The next part:
    <?php query_posts(‘category_name=press&showposts=10&offset=0’); ?>

    I need to keep that showposts=10 part to show the last 10 posts…. could be why it all broke?

    This is where I tried to change it to the other code with the ID’s – Just for the record my ID’s are blog=7 and press=3

    Can you let me know if this even makes even the most remote bit of sense?

    Thread Starter stirlingcreative

    (@stirlingcreative)

    Ok, this ALMOST did exactly what I wanted it to do….

    <?php query_posts(array(‘category__and&showposts=10&offset=0’ => array(3,7))); ?>

    The feed did show a mix of the 2 categories, BUT! – it didn’t show any more than the most recent and the next one, thr part where I have it saying showposts=10 didnt seem to register. Any ideas?

    <?php query_posts('category__and' => array(3,7) . '&posts_per_page=10'); ?>

    Thread Starter stirlingcreative

    (@stirlingcreative)

    thanks man, but that made the whole page vanish, I reverted though so its cool,

    I know I am so close yet so far from getting this to work…..

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Pulling posts using php’ is closed to new replies.