WordPress.org

Ready to get started?Download WordPress

Forums

Custom Index Page (4 posts)

  1. jpmaximilian
    Member
    Posted 6 years ago #

    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.

  2. designsimply
    Member
    Posted 6 years ago #

    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. http://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.

  3. designsimply
    Member
    Posted 6 years ago #

    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."
    http://codex.wordpress.org/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.

  4. jpmaximilian
    Member
    Posted 6 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.