1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Any PHP'ers out there? I have a little question.

Discussion in 'PHP & Perl' started by shapeshift3r, Apr 19, 2009.

  1. shapeshift3r

    shapeshift3r Junior Member

    Joined:
    Mar 26, 2009
    Messages:
    172
    Likes Received:
    45
    I made a blog using wordpress.

    I made categories to organize my posts.

    I wanted to display links to all posts in a given category on my sidebar when that category is selected.

    I got a widget to display the links. The way the widget works demands that you can only use one of its kind for each category. So I make one for each of my categories. Problem solved...not quite.

    When I visit a category page and click any of the post links the widget disappears. But I have a plan...

    I get a plug in that will allow me to continue to display the widget as long as certain PHP conditions are being met.

    Im currently using the conditions:
    is_single || is_category('category-slug-here')

    -BECAUSE-

    If I just use is_category the widget does not display on individual posts

    If I just use is_single the widget doesnt display on the category pages

    If I use both with an OR operator (||) it displays on both pages but because I used a different widget for each category it displays every widget.

    I only want to show links to the posts relevant to the category.

    What code could I use to do this?
    The plug in will allow absolutely any PHP, not jsut conditions.
    I just suck at PHP and have no idea how to do it.

    Cheers!
     
  2. oldenstylehats

    oldenstylehats Elite Member Premium Member

    Joined:
    Apr 10, 2008
    Messages:
    1,893
    Likes Received:
    1,196
    Moved to the appropriate section.
     
    • Thanks Thanks x 1
  3. MakeLemonade

    MakeLemonade Junior Member

    Joined:
    Mar 30, 2009
    Messages:
    148
    Likes Received:
    67
    Hiya.

    You're probably using the wrong plugin for the job. There's actually at least 7 out there for handling categories. I know because I just finished adapting one for some custom code I was doing yesterday. Here's a few to check out.

    http://wordpress.org/extend/plugins/breukies-categories-widget/

    http://wordpress.org/extend/plugins/extended-categories-widget/
    http://wordpress.org/extend/plugins/category-posts/

    If you're stuck on using your plugin, your "is_category" call looks like it's hardcoded. I just checked my code and I'm using a numeric category number. Not sure how you'd find out which category it is using code.

    Lemonade