• Resolved shua

    (@shua)


    When listing pages I have a bit of conditional code that reads a custom field and depending on its content will write out a class name (css). This class will then style the page link properly – this is exactly how the current_page_item class works.

    here is my code which I wrote into a new function:

    if ( get_post_custom_values($cur_page[‘id’],’new’) == ‘1’ )
    $css_class .= ‘ newVenue’;

    I have upgraded to wp2.5 and I see that template_functions_post.php is now post_template.php. I am uncertain how to procede to create the same functionality as in my pre wp2.5 site.

    thoughts?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Editing core code is generally frowned upon, but still…

    /wp-includes/classes.php
    Around line 560, in the start_el function:
    Change this:

    if ( !empty($current_page) ) {
    	$_current_page = get_page( $current_page );
    	if ( in_array($page->ID, (array) $_current_page->ancestors) )
    		$css_class .= ' current_page_ancestor';
    	if ( $page->ID == $current_page )
    		$css_class .= ' current_page_item';
    	elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    		$css_class .= ' current_page_parent';
    }

    To this:

    if ( !empty($current_page) ) {
    	$_current_page = get_page( $current_page );
    	if ( in_array($page->ID, (array) $_current_page->ancestors) )
    		$css_class .= ' current_page_ancestor';
    	if ( $page->ID == $current_page )
    		$css_class .= ' current_page_item';
    	elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    		$css_class .= ' current_page_parent';
    	if ( get_post_custom_values($current_page,'new') == '1' )
    		$css_class .= ' newVenue';
    }

    Thread Starter shua

    (@shua)

    Thanks!

    I modified classes.php, but it doesn’t look like it is reading the custom field correctly. I tried a != value and it returned the class for all elements in the loop (meaning it didn’t find a value for the key?)

    Thoughts?

    Check out the sidebar page listing here: https://www.seesawnetworks.com/explore/life-patterns or Venue Categories << this is how it should work ??

    Thread Starter shua

    (@shua)

    It is not reading what the $current_page is… thoughts?

    Thread Starter shua

    (@shua)

    here is a better url:

    https://www.seesawnetworks.com/explore/categories

    I have a custom field that specifies if the category (page element in wp) is ‘new’ or ‘coming soon’. If the value is ‘new’ then a class is set.

    What I am seeing is that $current_page is not getting a value? so the conditional does not see the custom field value resulting in the class not being set.

    thoughts?

    Thread Starter shua

    (@shua)

    my solution! woo hoo!

    if ( !empty($current_page) ) {
    			$_current_page = get_page( $current_page );
    			if ( in_array($page->ID, (array) $_current_page->ancestors) )
    				$css_class .= ' current_page_ancestor';
    			if ( $page->ID == $current_page )
    				$css_class .= ' current_page_item';
    			if ( get_post_meta($page->ID, 'new', true) == 'Soon' )
    				$css_class .= ' soonVenue';
    			if ( get_post_meta($page->ID, 'new', true) == '1')
    				$css_class .= ' newVenue';
    			elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    				$css_class .= ' current_page_parent';
    		}

    thx for your help Otto!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp2.5 upgrade… template_functions_post.php’ is closed to new replies.