WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Link category to page (8 posts)

  1. mastron
    Member
    Posted 6 years ago #

    Hi There

    I have a hard question, at least to me. I can sove it on a large way but I like it to be small.

    I have 10 categories and 10 pages.

    What i would like to happen is that the page sport only shows posts in the category sport. I know I can make 10 page templates with only the category post in it, but I was wondering if it is posible in one page.

    I was thinking of something like:

    if page title is sports show category=1

    else

    if page title is news show category=2

    else

    etc.

    But then in PHP .. which I am not good at.

    The website I am making is:
    http://www.kanaalhelmond.nl/web

    Thanks in advance.

  2. moshu
    Member
    Posted 6 years ago #

    Wrong approach. Do NOT use Pages - they are not for displaying posts.

    You need Category_Templates.

  3. mastron
    Member
    Posted 6 years ago #

    I need to use pages. My menu is built up on the pages I made, so a category list does not work for me.

    If I use a category template I have to make 10 category pages and I like to use one page.

    Is it posible and how?

  4. moshu
    Member
    Posted 6 years ago #

    I still think it is easier to change one line of code in the menu than changing how WordPress works... and if you are not styling them differently you don't even need Category Templates (or only one).

    Anyway, if you want to do it in your way - you are welcome. Just don't ask for help if you know better.

  5. mastron
    Member
    Posted 6 years ago #

    I understand what you are saying. I would prefer to do it that way and use category selection in my menu. But the thing is that I am using a plugin to show my pages:

    http://goudendouche.com/dropdown-menu-plugin/

    This plugin shows the pages and not the categories, please have a look at the site that I am working on:

    http://www.kanaalhelmond.nl/web

  6. mastron
    Member
    Posted 6 years ago #

    Got it:

    <?php

    if (is_page('Nieuws')) {
    query_posts('cat=4');

    } else if

    (is_page('Lokaal')) {
    query_posts('cat=5');

    } else if

    (is_page('Gemeente')) {
    query_posts('cat=6');

    } else if

    (is_page('Sport')) {
    query_posts('cat=7');

    } else if

    (is_page('Cultuur')) {
    query_posts('cat=8');

    } else {
    query_posts('cat=' . $events_cat . '&paged=' . $paged);
    }
    ?>

  7. lebonchat
    Member
    Posted 6 years ago #

    Does that code go into the page.php template? and/or index.php?

  8. lebonchat
    Member
    Posted 6 years ago #

    Nevermind... Got it! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic