+ Reply to Thread
Results 1 to 7 of 7

Thread: Category variable

  1. #1

    Default Category variable

    I'm trying to change the appearance of posts based on what category they are in. I was thinking of adding a conditional include statement to Single Post (single.php).

    I can get a static include to show on all posts by putting it directly before where the content is called up.

    For example (added the red to the file in between the existing lines)
    <div class="entry">
    <?php
    include("http://XXX.org/topofpost.php");
    ?>

    <?php the_content('<p>Read the rest of this entry &raquo;</p>'); ?>

    But to get the conditional include to work, I need to know the variable for the category. And I can tell cat_ID isn't what I need...

    if (cat_ID == '3') {
    include("http://XXX.org/topofpost3.php");
    }
    if (cat_ID =='4") {
    include("http://XXX.org/topofpost4.php");
    }

    In my installation I will only have one category for each post so there would not be a problem with having two categories...

    TIA,
    June

  2. #2
    Join Date
    Feb 2009
    Posts
    605

    Default

    Use is_category(); Usage here:

    You can use either the category id or the category as a parameter. More info here:

    http://codex.wordpress.org/Function_...ce/is_category

    Also, if you want to include a file without calling an absolute URL, save it on your stylesheet directory and call it like this:

    PHP Code:
    <?php include(TEMPLATEPATH '/file.php'); ?>
    All in all:

    PHP Code:
    <?php if ( is_category('5') ) {
    include(
    TEMPLATEPATH '/topofpost5.php');
    ?>
    Quote Originally Posted by junedodge View Post
    I'm trying to change the appearance of posts based on what category they are in. I was thinking of adding a conditional include statement to Single Post (single.php).

    I can get a static include to show on all posts by putting it directly before where the content is called up.

    For example (added the red to the file in between the existing lines)
    <div class="entry">
    <?php
    include("http://XXX.org/topofpost.php");
    ?>

    <?php the_content('<p>Read the rest of this entry &raquo;</p>'); ?>

    But to get the conditional include to work, I need to know the variable for the category. And I can tell cat_ID isn't what I need...

    if (cat_ID == '3') {
    include("http://XXX.org/topofpost3.php");
    }
    if (cat_ID =='4") {
    include("http://XXX.org/topofpost4.php");
    }

    In my installation I will only have one category for each post so there would not be a problem with having two categories...

    TIA,
    June

  3. #3
    Join Date
    Jul 2009
    Posts
    1

    Default Category variable

    Hello

    I want to use iMacros to automatically submit articles to article directories. I will be using different categories though, so I cannot use the Firefox addon to record a macro for each article site and fully automate it as this will record a specific category and I will want to vary this. Could anyone advise a script or variable to code for this?

    Thanks
    N
    Let me introduce myself.

  4. #4
    Join Date
    Feb 2009
    Posts
    605

    Default

    Sorry but I don't think that falls under Cutline support... But if anyone wants to help, please reply to this message preferably in a different thread.

    Quote Originally Posted by genroxbro View Post
    Hello

    I want to use iMacros to automatically submit articles to article directories. I will be using different categories though, so I cannot use the Firefox addon to record a macro for each article site and fully automate it as this will record a specific category and I will want to vary this. Could anyone advise a script or variable to code for this?

    Thanks
    N
    Let me introduce myself.

  5. #5

    Default

    Thank you for your help. I am now able to have different things appear at the top of my posts based on their category.

    I was not able to get the templatepath business to work so just put the exact links in the file.

    First - I had to get the list of categories and their number - then I created and uploaded what I wanted to show on the top (I used Dreamweaver). I wanted a submenu with a graphic to show for each of the different schools - but for the archived pages I just had text showing saying the page was archived.

    The I put the include statements in the single.php file. I put this after the div class = entry and the bit about read the rest of this entry.

    I may change where I put the files - but that is not the important thing - the important thing is to see the lines added to single.php so the tops change based on the category.

    <!-- START category TOPS -->

    <?php
    if ( in_category(5) ) {
    include('http://parentpage.org/top-hth0910.php/');
    }

    if ( in_category(6)) {
    include('http://parentpage.org/top-hthi0910.php/');
    }

    if ( in_category(10)) {
    include('http://parentpage.org/top-htm0910.php/');
    }

    if ( in_category(7)) {
    include('http://parentpage.org/top-hthma0910.php/');
    }

    if ( in_category(11)) {
    include('http://parentpage.org/top-htmma0910.php/');
    }

    if ( in_category(114)) {
    echo "THIS PAGE IS ARCHIVED - LINKS MAY NOT WORK.";
    }

    if ( in_category(109)) {
    echo "THIS PAGE IS ARCHIVED (07-08) - LINKS MAY NOT WORK.";
    }

    if ( in_category(116)) {
    echo "THIS PAGE IS ARCHIVED (08-09) - LINKS MAY NOT WORK.";
    }

    ?>

    <!-- END category TOPS -->

  6. #6

    Default Category variable

    I have been trying that but I seem to always miss the right query,

    but its only the query not some global variable?

    I try some more copy pasting to see if I can get lucky

  7. #7
    Join Date
    Feb 2009
    Posts
    605

    Default

    Could you please be a little more specific?



    Quote Originally Posted by BEapsparfrief View Post
    I have been trying that but I seem to always miss the right query,

    but its only the query not some global variable?

    I try some more copy pasting to see if I can get lucky

+ Reply to Thread

Similar Threads

  1. Different header image per category. How?
    By ungefragt in forum Community Exchange
    Replies: 6
    Last Post: 04-14-2010, 08:18 AM
  2. Category not showing
    By AineNi in forum Bugs & Fixes
    Replies: 2
    Last Post: 02-08-2010, 09:12 PM
  3. Category page
    By pau.barrena in forum Posts, Pages, Comments
    Replies: 2
    Last Post: 10-19-2009, 04:45 PM
  4. appearance of category-list
    By merderein in forum Cutline Mods
    Replies: 4
    Last Post: 09-22-2009, 02:34 PM
  5. Post category display for Cutline 2.2?
    By wilfrid in forum Bugs & Fixes
    Replies: 2
    Last Post: 07-30-2009, 04:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts