WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp2.5 upgrade... template_functions_post.php (6 posts)

  1. shua
    Member
    Posted 6 years ago #

    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?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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';
    }
  3. shua
    Member
    Posted 6 years ago #

    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: http://www.seesawnetworks.com/explore/life-patterns or Venue Categories << this is how it should work ;)

  4. shua
    Member
    Posted 6 years ago #

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

  5. shua
    Member
    Posted 6 years ago #

    here is a better url:

    http://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?

  6. shua
    Member
    Posted 6 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic