• Resolved miriammp

    (@miriammp)


    Hello,
    I’m trying to create a single-portfolio.php template for the Pods Custom Post Type “Portfolio” which I created. Would anybody know how to convert the following code into php so it works with wordpress…?

    ` <div id=”port-individual”>
    <div id=”col_one”>
    <img src=”{@image_one}”/>
    <img src=”{@image_two}”/>
    <img src=”{@image_three}”/>
    </div><!–#col_one–>

    <div id=”col_two”>
    <h3>{@post_title}</h3>
    <p> Client: {@client}</p>
    <p> Category: {@project_category}</p>
    <p> Website: <a href=”{@website}”>{@website}</a></p>
    <p>Challenge+Solution: {@post_content}</p>
    </div><!–#col_two–>

    </div><!–#port-individual–>`

    “Post_title”, and “post_content” are regular wordpress fields. “project_category”, and “clients” are Pod taxonomies. “website”, “image_one”, “image_two”, “image_three” are the pod fields of pod custom post type called “Portfolio.

    I’d really appreciate ANY lead or help I can get to create a template for the custom post type.
    (Genesis sample child theme being used.).

    Many thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    As you probably surmised, each pod field can be replaced by a PHP equivalent. {@post_title} would become <?php the_title(); ?>

    All the data exists in some form in the DB so there will always be some way to get at it. In most cases, there will be a WP function that will get the data for you. I don’t use Pod, but I would expect a pod taxonomy still uses the taxonomy tables, so you can use generic WP taxonomy functions to get the terms you need. And pod fields should be in post meta, so WP post meta functions should get the fields you need.

    If all else fails, get data out of the DB using $wpdb methods. It may be useful to view your DB with phpMyAdmin so you know where the data actually resides, under which keys. The Codex will be a good reference in helping you locate the proper WP functions. Without knowing how the data is actually stored, this is about all I can say on the subject.

    If you get stuck on a particular item, locate it with phpMyAdmin, select the associated row, then export it in XML format and paste the output at pastebin.com. Provide the link here, and someone should be able to give you the PHP to get it output from your template. Good luck!

    Thread Starter miriammp

    (@miriammp)

    wow, thanks so much for this lead. I’m so new to php, I was having a difficult time pulling up / understanding where to use the basics! Alright, so I was able to code most of it, as seen below. The only issue I’m having is with $website:
    a) It doesn’t display as a clickable link. How would I incorporate the tag within the php?
    b) I would love if http:// wouldn’t show up. As in, it should only say “ww.wp.xz.cn”. Is there a function for that?

    <?php get_header(); ?>
    <section class="wrap">
    		<div id="port-individual">
    			<section class="port_col_left">
    
    				<?php
    					if ( get_post_meta( get_the_ID(), 'image_one', false ) ){
       						$image_array = get_post_meta( get_the_ID(), 'image_one', false );
    					}
    					if ( $image_array ) {
      						 echo '<ul>';
       						 foreach ( $image_array as $image ) {
           					 $class = "post-attachment mime-" . sanitize_title( $image->post_mime_type );
            				 $thumbimg = wp_get_attachment_image( $image['ID'], 'large');
            				echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';
        					}
        				echo '</ul>';
    					}
    				?>
    
    			</section><!--.port_col_left-->
    
    			<section class="port_col_right">
    				<?php
    					if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        				<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            				<h2><?php the_title(); ?></h2> 
    
            				<div class="entry">
               					 <?php the_content(); ?>
            			</div>
    
            			<p><?php echo get_the_term_list( $post->ID, 'client', 'Client: ', ', ', '' ); ?> </p>
    
            			<p><?php echo get_the_term_list( $post->ID, 'project_category', 'Category: ', ', ', '' ); ?> </p>
            			<?php $website = get_post_meta($post->ID, 'website', true);?>
            			<p><?php if($website != '') {
            					echo  $website;
     						}?>
     					</p>
       					</div>
        				<?php endwhile; endif;
        			?>
    			</section><!--.port_col_right-->
     	</div><!--#port-individual-->
    </section><!--.wrap-->
    
    <?php get_footer(); ?>

    Thanks again!!

    Moderator bcworkz

    (@bcworkz)

    Nice work for a newbie! You should be proud 🙂

    For a clickable link, start with the original Pods code and substitute in <?php echo $website; ?> for {@website}. To remove the http:// bit from the link text, use one of the native PHP string manipulation functions to strip out the text. str_replace() could do this, except you need to account for the possibility of https:// as well. This situation is easily addressed by using the regexp (regular expression) variant of str_replace: preg_replace(). This function involves a lot more overhead than str_replace, but regexp can be very powerful.

    This should work for you, but it is untested:
    Website: <a href="<?php echo $website; ?>"><?php echo preg_replace('|https?://|', '', $website ); ?></a>

    The preg_replace essentially says replace anything matching the regexp with nothing and return the result. The regexp tries to match anything between the outer two characters of the regexp in $website. Regexp has a rich set of characters that have special meaning. In our case all the characters but the ? are literals to match against $website. The ? means the preceding character (s) is optional. If you had a need to match a special character, it is escaped by preceding it with \.

    Thread Starter miriammp

    (@miriammp)

    thanks 🙂 I’m trying 🙂
    The code works perfectly, AND you got me to understand what I’m doing too.
    Thanks loads again!

    Thread Starter miriammp

    (@miriammp)

    solved

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Pods Single Template’ is closed to new replies.