• I’m trying to create a second index page that is linked to my wordpress database, but only displays posts from one specific category. I don’t know if this is even possible, but if it is and anyone could point me in the right direction I’d appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, here’s how to do it for the main page, but why not use the regular category archive pages instead of creating a second index file? Category pages should already exist (i.e. https://telthorst.net/category/politics/).

    In your template index.php file (*make a backup before editing*), right after the line that looks like <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    Add this:

    <!-- Exclude all posts not in category 3. -->
    <?php if (!in_category('3')) continue; ?>

    Replace “3” with the category you wish to use.

    To find the category ID, go to wp-admin > Manage > Categories > {your-category-name}. When you’re on the edit category page, you should see &cat_ID=# in the url query string.

    Actually, the query_posts() template tag would probably be an even better way to do what you want, one of the uses listed in the documentation is to “show posts from only one category.”
    https://codex.www.ads-software.com/Template_Tags/query_posts

    You could create a Page Template and use the query_posts() template tag in it. Then create a new page in WordPress and assign the custom Pate Template to it.

    See Creating Your Own Page Templates for more details.

    Thread Starter jpmaximilian

    (@jpmaximilian)

    I understand the page template stuff, but I’m confused about creating a new page. Could you elaborate on that? Are you talking simply about a new page within wordpress or uploading a new page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Index Page’ is closed to new replies.