Cipherlad
Member
Posted 11 months ago #
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:
http://wordpress.org/support/topic/plugin-wp-subdomains-331-working?replies=26
ovidiuionita
Member
Posted 11 months ago #
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 http://wordpress.org/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.
Cipherlad
Member
Posted 11 months ago #
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.
ovidiuionita
Member
Posted 11 months ago #
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'); ?>