• Hi All,

    I have about 20 categories of post types on my wordpress site, and depending on which category it is in, I want a “Go Back” link to take the user back to a certain page.

    Is this possible using a single post template, or do I need to create 20 templates, 1 for each category of post?

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • There are several ways you could do this, but what about using one of the category conditional tags.

    You can find them here: Category Template Tags

    if ( is_category( 'my category' ) {
      // code for go back link goes here
    }

    Just create a single category template and then use this code in the php file:

    switch( $cat ) {
        case 1:
            echo "Something in category id 1";
            break;
    
        case 2:
            echo "Something in category id 2";
            break;
    }

    $cat is a global variable containing the id of the category currently being viewed. Let me know if this works.

    Thread Starter craigs85

    (@craigs85)

    So I’ve added this to my single.php file, but it doesn’t work. The page is empty now!

    <?php
    if ( is_category( ‘treepollarding’ ) {
    echo ‘<p>Tree Pollarding</p>’;
    }
    ?>

    What have I done wrong?

    Thread Starter craigs85

    (@craigs85)

    Hi,

    Could somebody help me with either of the suggestions above?

    I basically want a different back link to be used on the single post page depending on what the category is that the post belongs to.

    Both suggestions above seem really good, I just don’t know how to code it properly and what file to put it in?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post category templates’ is closed to new replies.