WordPress.org

Ready to get started?Download WordPress

Forums

Plugin / Navigation help (4 posts)

  1. armstrong1118
    Member
    Posted 6 years ago #

    I am using the following function that I coded (I am VERY new to this) to take the catgory page that someone is looking at to set a variable that I would like to use in my sidebar.

    <?php
    function myfunc(){
    	global $myVar;
    	if (is_category(16)) {
    			$myVar = 16;
    	}
    	return $myVar;
    }
    ?>

    The only problem is that I think im using the code wrong in the sidebar.php

    <?php
    if (is_home()) {
            echo "<ul>";  wp_list_cats('optionall=0&sort_column=name&list=1&children=0');
            echo "</ul>";
    } elseif (is_single() && $myCtg == "16") {
    		echo "<ul>";	wp_list_bookmarks('category_before=<span>&category_after=</span>&categorize=1&category=16&show_images=0&show_description=0&orderby=url');
    		echo "</ul>";
    }
    ?>

    because I also have an else set up to catch anything that doesnt work, and that is what keeps showing up in my sidebar.

    Any ideas on how I could make this work, or am I going about this in an entirely wrong way?

    Thanks

  2. Jeremy Clark
    Moderator
    Posted 6 years ago #

    Well for one thing when you declared the variable it was myVar then in your sidebar your using $myCtg.

    Also instead of troubleshooting code why not describe what you're trying to do, there is probably a much simpler way.

  3. armstrong1118
    Member
    Posted 6 years ago #

    sorry, I was just trying to generalize everything for the post and missed the second halfI guess, all the variables are set to $myCtg

  4. armstrong1118
    Member
    Posted 6 years ago #

    Update - I know for a fact that the function works ok, the problem is in the sidebar, for some reason how I address the variable in the if statement isnt catching.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.