• I need to know how to filter posts by category in the home page. The category is passed as the subdomain in the url. I don’t think I’m looking for a plugin as the ones I’ve looked at ask for a specific category to be defined in the dashboard, and this should be a dynamic solution.

    WP is still confusing for me, I have little idea how everything ties in. I suspect the plugin I’m using extracts the category/subdomain from the url, to use in other page filters, so it may be putting the category into some global variable. I don’t know, and don’t know how to find that out. The plugin is the modified versin of WP-Subdomains by lontongcorp:

    https://www.ads-software.com/support/topic/plugin-wp-subdomains-331-working?replies=26

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can do this by editing the your theme`s index.php file and adding the following code before the loop:

    <?php query_posts('cat=xx); ?>

    where xx is the ID number of the category you want to display, so your index.php file should look something like this:

    <?php query_posts('cat=xx); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    ......

    You can also define the displayed category by its slug using

    <?php query_posts('category=category-slug-name'); ?>

    Also, you may want to check https://www.ads-software.com/support/topic/only-show-posts-from-a-particular-category-on-homepage where the explain everything in more detail, and even show how to limit your query.

    Thread Starter Cipherlad

    (@cipherlad)

    A clear, concise, and complete answer. This is exactly the pointer I needed. Thank you. I’ll try this out over the weekend and post back if there are any problems.

    Just a correction: I copied the code directly from the link I mentioned at the end and forgot to put an apostrophe after xx.
    The correct code is:

    <?php query_posts('cat=xx'); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to filter categories in index.php’ is closed to new replies.