WordPress.org

Ready to get started?Download WordPress

Forums

if($_REQUEST['cat']) with permalinks on (9 posts)

  1. Tobias Jordans
    Member
    Posted 9 years ago #

    Hi!

    Before I started using Permalinks i used code like if($_REQUEST['cat']) to add special code for my pages where the category-postings are displayed ...

    Now I cannot do this anymore since there is no more "request"-variable. My URL is now http://www.x.com/category/name/

    Any ideas how to do what I did before but with permalink on?

    Thanks

  2. Minna
    Member
    Posted 9 years ago #

    How about using is_category() that tells you if you are in the category archives -- that is, it is true if you are in the category archives...
    Those are called Conditional Tags, and you can do all kinds of great things with them! :)

  3. Tobias Jordans
    Member
    Posted 9 years ago #

    Thats great.
    I hoped sb would point me to somthing like this :)

    Thanks a lot!

  4. Tobias Jordans
    Member
    Posted 9 years ago #

    But: If I use my _request-version I have another possibility: I can read the cat ID and page ID that is written in the URL
    I cannot do this with permalinks and it seems to be impossible as well with the conditional tags.

    Suggestions?

  5. Minna
    Member
    Posted 9 years ago #

    You can get the category number with some code (it's been discussed just recently) if you need it outside the loop (I guess inside the loop, there's template tag for it). With is_category you can specify which category the condition is true for, e.g. is_category('8'); or the same with page, is_page('about-me')

  6. Tobias Jordans
    Member
    Posted 9 years ago #

    Thx for reply, Minna.

    The problem: is_category just returns true, not the cat-number.
    What I want do do is to echo the description and name of the cat above my posting.

    So with this technik i would have to write a condition for each cut ---- mh.... wait --- there is another way --- i will test it :)

  7. Minna
    Member
    Posted 9 years ago #

    I do this:
    if ( is_category() ) {
    <h1><?php single_cat_title('',true); ?></h1>
    <?php echo category_description(); ?>
    }

    to show the category name and description in the archives

  8. Tobias Jordans
    Member
    Posted 9 years ago #

    OK, this way it works:

    for ($i = 1; $i <= 60; $i++) {
    if (is_category($i)) {
    echo "...".get_catname($i)."... ";
    if (category_description($i))
    echo "...".category_description($i)."...";
    echo "

  9. ";
    }
    }

    Would be perfect to find a .countCategory() to replace the value 60 but is fine so.

  • Tobias Jordans
    Member
    Posted 9 years ago #

    @your code:

    before working with permalinks i could write stuff like
    cat=1+33+20
    that would show the postings belonging to all of them.

    That is why I use this more complicated way.

    Unfortunatelly right now I am not shure if I can do this nested cat-call anymore but I am testing...

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags