• I would like to change the background of a post. not all just some, i defined the classes for each post. how would i get it to display on category.php search.php and single.php?

    what code would i use on the page and where ?

    here is the css for the child theme of 2011

    /* body class colrs  */
    
    body.year-member div#content {
    	background-color: #0F0;
    }
    
    body.half-year-member div#content {
    	background-color: green;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • to target individual posts, you possibly need to consider using post_class() https://codex.www.ads-software.com/Function_Reference/post_class

    Thread Starter Scott@adszoom

    (@scottadszoom)

    Hay ya thats helpful but im using wishlist member plug in and using this code

    <?php
    // https://www.gravityhelp.com/forums/topic/changing-the-background-color-of-a-post
    // filter the body class
    add_filter( 'body_class', 'adzoom_wishlist_member_classes' );
    
    // function to add body class based on wishlist member weekly, 180 day or 365 day
    function adzoom_wishlist_member_classes ($classes) {
    
    	// grab the current user's wishlist member levels
    	global $current_user;
    	$user_id = $current_user->ID;
    	$levels = wlmapi_get_member_levels($user_id);
    	$levels = $levels['levels']['level'];
    
    	// these three if statements will all run, no matter what, in case there are multiple membership levels possible for a member?
    	// not sure if that's possible, but the wlmapi_get_member_levels returns an array, which could be multiple membership levels
    
    	// add the membership levels to the body class
    	if(in_array(365, $levels)) {
    		// add 'year-member' to the $classes array
    		$classes[] = 'year-member';
    	}
    	if(in_array(180, $levels)) {
    		// add 'half-year-member' to the $classes array
    		$classes[] = 'half-year-member';
    	}
    	if(in_array('weekly', $levels)) {
    		// add 'week-member' to the $classes array
    		$classes[] = 'week-member';
    	}
    
    	// return the $classes array no matter what
    	return $classes;
    }
    ?>

    then trying to change the background on some posts using this

    <body <?php body_class($class); ?>>

    in the header.php file

    what do you think? Im not using a custom template for category.php just this
    https://www.nichedeliverysystem.com/category/jobs-classifieds/

    so the 1st 2 ads / posts should have a yellow back ground but dont??
    can you see the issue?

    Thread Starter Scott@adszoom

    (@scottadszoom)

    it checks member class in an array then well you know…

    your code might only work for a post in single post view; not for individual posts in an archive page.

    for individual posts in an archive or search result page, you possibly would need to rewrite the code for using ‘post_class()’ and for using the post author id instead of user id (?).

    I can’t find ‘wishlist member’ plugin in the plugins’ list – is it a commercial plugin?

    Thread Starter Scott@adszoom

    (@scottadszoom)

    Hi

    Ya its https://member.wishlistproducts.com/

    Is a common membership plug in I see what your saying but if we use the

    <body <?php body_class($class); ?>>

    in the header.php it should be called on each of the above named pages. is there something maybe we add to the search,auth0r,archive, single.php maybe that would do the trick? this dose not even work in single post view mode so im baffled. Tried it in the default 2011 theme as well with 0 success. The code I wrote / with help just checks the array for the member level and then should return classes.
    can I do the same thing without tapping into the plug in? somehow just get some bit of info from somewhere else that separates the member levels?
    I need this plug in thu built the theme around it like a dummy lol

    I just want a diff background for each.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘calling a body class’ is closed to new replies.