WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Side-by-side columns, different categories? (8 posts)

  1. yosemite
    Member
    Posted 7 years ago #

    Tried wp-hackers, no response there, so:

    Trying to develop a theme (at test.samdevol.com) that has 2 columns and a sidebar. I'm trying to use the query_posts (running 2 separate loops in index.php) and have success with hard-coding e.g.; query_posts('cat=2,-11&showposts=10'); in each separate loop, but when I try to make use of Ozh's Theme Tool Kit to allow users control of which categories are displayed in the columns it breaks. Whether I build a function and use it:
    $cats2=corporate_slave_col2cats() . corporate_slave_postquant();
    query_posts($cats2); echo $cats2;

    or I use variables:
    global $corporate_slave; $cats2=
    "'".$corporate_slave->option['col2cats']. '&showposts='.
    $corporate_slave->option['postquant']. "'"; query_posts($cats2); echo $cats2;

    I end up with the correct string echoed from $cats2, but it just displays all categories.

    Any suggestions, ideas?

  2. Chris_K
    Member
    Posted 7 years ago #

  3. yosemite
    Member
    Posted 7 years ago #

    That was the basis for my setup. And it works quite well (when I enter the arguments for query_posts() manually), but I added an entry in Theme Options so the owner/user could enter which categories go in which column.

    As soon as I apply those as variables/functions with query_posts() it seems to break.

    (As we discussed in IM, I suspect it has to do with me not passing 'real' strings? Still researching.)

  4. yosemite
    Member
    Posted 7 years ago #

    An example: If I use query_posts('cat=3&showposts=10') it works fine.

    If I use:
    query_posts($cats2); (note that echo $cats2; returns 'cat=3&showposts=10') it breaks and just displays all posts/categories.

  5. MichaelH
    Member
    Posted 7 years ago #

    What happens if you don't use the ' on both ends of the $cats2 variable?

  6. yosemite
    Member
    Posted 7 years ago #

    Tried a number of variations (this time echo $cats2; returns cat=3, but with or without single-ticks it behaves the same (ignores category selection/argument).

  7. MichaelH
    Member
    Posted 7 years ago #

    I'm sure you've seen this but I'll point it out just in case:
    http://codex.wordpress.org/Template_Tags/query_posts#Passing_variables_to_query_posts

  8. yosemite
    Member
    Posted 7 years ago #

    Thanks MichaelH, you were right, I just had some mental block thing going.

    I have been referring to that page extensively, but I was also handling parsing the string in the /[themename]/functions.php file (using Ozh's Theme Toolkit) at some point and borked it up apparently. Once I gave up on any formatting for the ticks (or cat=)in the /[themename]/functions.php and just followed your link example, it worked. Imagine that. *blushes*

    Thanks again ;')

    Working code:
    <?php $cat_id='cat=' . $corporate_slave->option['col1cats']; ?>
    <?php query_posts($cat_id); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic