• Resolved acornrevolution

    (@acornrevolution)


    I am making a custom widget sidebar. I have a conditional statement that shows a list of recent posts based on the category. Below that, I would like to include a list of resources based in a file. The file is the same name as the category. How do I call the file in the PHP include() code so that it grabs the current category name?

    I’ve tried something like

    <?php include("http://www.website.com/$category.inc"); ?>
    but it didn’t work.

    THANKS!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I haven’t tested it, but try:

    <?php include(“http://www.website.com/&#8221;.the_category();.”.inc”); ?>

    You may needs spaces before and after the dots.

    Thread Starter acornrevolution

    (@acornrevolution)

    I had to remove the first set of quotes to get it to work with a plugged in file name, i.e:
    <?php include(TEMPLATEPATH . '/lists/games.inc'); ?>

    Then I tried it with your code, using no spaces and spaces, and neither worked.

    Also, will this pull the ID or the name? The files are named after the category names/slugs, so I need to make sure it pulls that.

    THANKS!

    Thread Starter acornrevolution

    (@acornrevolution)

    <?php
    $cat = single_cat_title();
    include(TEMPLATEPATH . '/lists/$cat.inc'); ?>

    This is getting me closer, but it’s only printing the category title instead of including it as part of the file name…

    Any ideas??

    Thread Starter acornrevolution

    (@acornrevolution)

    Thanks to some IRC help, this does the trick:

    <?php
    $cat = single_cat_title("", false);
    include(TEMPLATEPATH . "/lists/$cat.inc"); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP Include file based on category name’ is closed to new replies.