• I am trying to get this piece of code to bypass the theme’s options for what category populates a slider on my site’s posts, such as this one: https://www.theresident.net/web-video/your-part-in-global-warming/

    The reason I’m trying to bypass the options in the theme options menus is because I have the slider on the homepage set to show all categories in that theme options menu (which works fine), but I’d like the slider on the post pages to show posts that are within the same category of the selected post alone.

    I’d like the slider to be populated with the category “web-video” in the above example. The code that determines what category populates the slider is below. I am guessing I should remove the “if $myOptions” portions and just set the $category = and the $posts = to what I want. When I put in the number for $posts = , I see the correct number there. But I am not sure what to enter for $category = to populate the slider with the category reflected in the post’s slug. Any help would be great!

    <?php $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    if ($myOptions[‘bottom_cat’]) {
    $category = $myOptions[‘bottom_cat’];
    } else {
    $category = 0;
    }
    if ($myOptions[‘bottom_posts’]) {
    $posts = $myOptions[‘bottom_posts’];
    } else {
    $posts = 0;
    }
    query_posts(“cat=$category&paged=$page&posts_per_page=$posts”);
    while ( have_posts() ) : the_post() ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • $get_category = get_the_category();
    $category = $get_category[0]->category_nicename;

    I’m thinking that might work?

    Thread Starter theresident

    (@theresident)

    Hi there! Thanks so much for the response, I am at a loss!

    That didn’t seem to work, though I might not have implemented it correctly. Is this what you meant? This is what the code looks like:

    <?php $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    {
    $get_category = get_the_category();
    $category = $get_category[0]->category_nicename;
    }
    {
    $posts = 3;
    }
    query_posts(“cat=$category&paged=$page&posts_per_page=$posts”);
    while ( have_posts() ) : the_post() ?>

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $get_category = get_the_category();
    $category = $get_category[0]->category_nicename;
    $posts = 3;
    
    query_posts("cat=$category&paged=$page&posts_per_page=$posts");
    while ( have_posts() ) : the_post() ?>
    Thread Starter theresident

    (@theresident)

    No change with that. Ugh! Thanks for any input. It seems like it should be an easy thing to do but I’m stumped!

    Yeah, It’s possible I was leading you astray here… I jumped to code based on yours, without reading your description well enough of how you were using it….

    this is running on the single.php template?

    Thread Starter theresident

    (@theresident)

    Yes, it’s running on the single.php.

    I have it running normally on index and am trying to finesse the single.

    ALright, what’s the context here? The slider is a loop, is it running inside of another loop? Or above it?

    Thread Starter theresident

    (@theresident)

    I am a bit of an idiot, so I’m not sure.

    The <?php endwhile;?> line happens right after it, so I think it’s still in the loop, yes?

    Thank you so much for taking a peek!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘determining the variable for $category =’ is closed to new replies.