• Hi apologies in advance as I am sure this is a dumb question. I have been reading the Codex and just starting to have a delve under the covers as it were in terms of customising some of my content.

    So for example if I want to display posts from a certain category I understand how I can do that by adding get_posts with a set of parameters – the question is though – where do I add this code? It doesn’t make sense to add it into an existing template file as I’m thinking it would form part of a page or a post. So for example if I have a post content with a few paragraphs of text then I want to say “and here is a list of what we are talking about” and then list posts from a certain category. Do I just make a new template file and code it in there and then assign that post to use that template file (can I do that?). What about if I want 10 pages like this, each listing a different category – 10 template files required?

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Time for one of my all time favorite plugins! Miniloops sounds like an exact match. Study the Other Notes page to understand how to modify your shortcode to only display posts from a certain category.

    I have used this plugin probably a hundred times for things like this. Post again here with your specific needs if you have any trouble.

    Thread Starter tonysab

    (@tonysab)

    Thanks – I should have mentioned that I have previously used a plugin for this – list category posts – but I would like to know how to do it myself, if possible. Thanks.

    Gotcha. Well there’s still tons of cool options. Based on your description above, I might consider making one template that lists your posts below the content. Then I’d create a custom field on your posts where you can select or enter the category to use. Then you just set a variable in your query to be the value in the custom field.

    In the end you will just make a post and enter the category in the custom field. This could be a dropdown, checkbox, radio group, text field, etc.

    Of course if you wish to show posts that are in the SAME category as the one you are writing, there are easier ways to do that. What I described would be useful only if you are doing something different each time but in the same visual format.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using get_posts – where should I add this?’ is closed to new replies.