ThemeShaper Forums » Thematic

[closed]

Trouble getting custom field to work

(1 post)
  • Started 12 years ago by krowchuk
  • This topic is not resolved
  1. Hi,

    I have this code in a left sidebar in my current non-Thematic theme and am trying to bring everything over to Thematic.

    <?php global $page;
    //global var for what page we are on
    
    if($page == '' || !isset($page)){ $page=1; }
    // set the var to 1 if it is not set
    
    $the_sidebar_array=get_post_meta($post->ID,'sidebar-photos-array',true);
    //get custom field
    
    if(strpos($the_sidebar_array,',')!=''){
    //do this if comma
    
    $the_photos=explode( ',',$the_sidebar_array );
    //create a real array from comma sep custom field value
    
    array_unshift($the_photos,'');
    //add blank val to 0 array key to make it easier to match page number
    
    $the_image = wp_get_attachment_image_src( $the_photos[$page],'full',false );
    //get image thumbnails src for the image
    
    if( !empty ($the_image)) {echo '<img class="centered" src="'. $the_image[0].'" />';}
    //if it has image, echo it out
    
    }else{
    //do this if no comma
    
        if($the_sidebar_array !=''){
        //just making sure it is really a value - we don't want and error if blank
    
        $the_image = wp_get_attachment_image_src( $the_sidebar_array,'full',false );
        //get image thumbnails src
    
        echo '<img class="centered" src="'.$the_image[0].'" />';
        //if it has image, echo it out
        }
    }
    
    ?>

    I use this custom field on some pages (not posts) that have very long articles broken up using the wordpress nextpage tag. Eg: a 5 page article will have a unique images that displays in a sidebar to the left of the content. Each page in the article has a unique image. The custom field uses 'sidebar-photos-array' and a comma separated list of the image number that wordpress generates. eg: 25,50,65,75 etc.

    This works very well in my current theme, I have not had any luck getting it to work in Thematic.

    Here is how I am attempting to use it in Thematic, in my child functions.php file:

    // Add divs into the main aside using abovemainasides and belowmainasides
    function wrap_above() { ?>
    <div id="primary-wrap" class="aside main-aside">
      <ul>
        <?php if ( is_page(array('911','209','207','211','222','219','224')) ) { ?>
    
          <?php global $page;
    	//global var for what page we are on
    
          if($page == '' || !isset($page)){ $page=1; }
    	//set the var to 1 if it is not set
    
          $the_sidebar_array=get_post_meta($post->ID,'sidebar-photos-array',true);
    	//get custom field
    
          if(strpos($the_sidebar_array,',')!=''){
    	//do this if comma
    
          $the_photos=explode( ',',$the_sidebar_array );
    	//create a real array from comma sep custom field value
    
          array_unshift($the_photos,'');
            //add blank val to 0 array key to make it easier to match page number
    
          $the_image = wp_get_attachment_image_src( $the_photos[$page],'full',false );
    	//get image thumbnails src for the image
    
          if( !empty ($the_image)) {echo '<img class="centered" src="'. $the_image[0].'" />';}
    	//if it has image, echo it out
    
    	}else{
    	//do this if no comma
    
    	if($the_sidebar_array !=''){
    	//just making sure it is really a value - we don't want and error if blank
    
    	$the_image = wp_get_attachment_image_src( $the_sidebar_array,'full',false );
    	//get image thumbnails src
    
    	echo '<img class="centered" src="'.$the_image[0].'" />';
    	//if it has image, echo it out
    		}
    	}
    
          ?>
    
    <?php } else { ?>
    
    	<?php the_post_thumbnail(); ?>
    
    <?php } ?>
    	<?php $postid = get_the_ID(); ?>
          		<div class="callout-caption">
           			<h3><?php echo get_post_meta($postid, 'callout_caption', true); ?></h3>
          		</div><!-- end callout-caption -->
          	</ul>
    
    <?php
    }
    add_action('thematic_abovemainasides','wrap_above');
    
    function wrap_below() {
    ?>
    	</div><!-- end primary-wrap -->
    <?php
    }
    add_action('thematic_betweenmainasides','wrap_below');

    Here is what I get, the conditional statement works, I do get the regular thumb on all other pages except those in the is_page array, the pages in the array don't show any images (I don't have featured images attached to those pages. The Caption custom field displays.

    So, it is working for the most part, I just can't figure out why the array of photos is not being displayed.

    Anyone able to help? Please? Been struggling with this for over a week.

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.