Adding Portfolio Inside Custom Post

Homepage Community Forums Epik Theme Support Adding Portfolio Inside Custom Post

  • This topic has 6 replies, 2 voices, and was last updated 9 years ago by Eric.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #15425
    hoolamonster
    Customer

      So I’m working with a custom template *page. I’m more comfortable using custom fields which is why I went this direction. I could not get them to work with the genesis loop

      so lets say this is my template file

      <?php
      
      // Template Name: My Lander
      
      /**
       * Custom Fields
       *
       */
      
      function bsp_custom_field() {
      // Image container
      	echo '<div class="feature-container"><div class="wrap"><div class="feature-image-container-1">';
      		$test = get_post_meta( get_the_ID(), 'main_title', true );
      			if( $test ) {
      				echo '<div class="wrap"><div class="feature-title">';
      					$content = get_post_meta( get_the_ID(), 'main_title' , true );			
      					echo '<h1>' . ( $content ) . '</h1>';
      				}
      					echo '</div></div>';
      	echo '</div></div></div>';
      // END Image container
      
      add_action( 'bsp_content_area', 'bsp_custom_field' );
      
      // Remove 'site-inner' from structural wrap
      add_theme_support( 'genesis-structural-wraps', array( 'header', 'footer-widgets', 'footer' ) );
      
      // Build the page
      get_header();
      do_action( 'bsp_content_area' );
      get_footer();

      I’ve copied this from a few sources to get custom fields working ; )

      Anyhow, Im wondering how I can integrate the portfolio functions into my template inside my own container like you see above (within the custom field function). Thus, displaying the portfolio inside my custom template wherever I choose to put it. For example, if I was writing a page about car engines and I had blog posts about engines I could call and display that somewhere on my page.

      Then I’m hoping I can use the query_args to call a specific category of posts relevant to the page.

      #15440
      hoolamonster
      Customer

        So I have it working correctly I just need to work the styling. If anyone see’s a way to improve this please let me know.

        <?php
        
        // Template Name: My Lander
        
        function my_custom_field() {
        // Image container
        	echo '<div class="feature-container"><div class="wrap"><div class="feature-image-container-1">';
        		$test = get_post_meta( get_the_ID(), 'main_title', true );
        			if( $test ) {
        				echo '<div class="wrap"><div class="feature-title">';
        					$content = get_post_meta( get_the_ID(), 'main_title' , true );			
        					echo '<h1>' . ( $content ) . '</h1>';
        				}
        					echo '</div></div>';
        	echo '</div></div></div>';
        // END Image container
        // Nav Container
        	echo '<div class="s-nav-wrap">';
        		$test = get_post_meta( get_the_ID(), 'sticky_nav', true );
        			if( $test ) {
        					$content = get_post_meta( get_the_ID(), 'sticky_nav' , true );			
        					echo '<ul id="s-nav">' . ( $content ) . '</ul>';
        				}
        	echo '</div>';
        // END Nav Container		
        // Image container
        	echo '<div class="feature-container"><div class="wrap"><div class="feature-image-container-2">';
        		$test = get_post_meta( get_the_ID(), 'main_title', true );
        			if( $test ) {
        				echo '<div class="wrap"><div class="feature-title-2">';
        					$content = get_post_meta( get_the_ID(), 'main_title' , true );			
        					echo '<h1>' . ( $content ) . '</h1>';
        				}
        					echo '</div></div>';
        	echo '</div></div></div>';
        // END Image container
        }
        add_action( 'my_custom_fields_area', 'my_custom_field' );
        
        //Adds Page Content
        add_action( 'genesis_before_loop', 'epik_do_portfolio_content' );
        function epik_do_portfolio_content() {
            echo '<div class="entry-content entry-portfolio" itemprop="text">' . get_post()->post_content . '</div>';
        }
        
        // Loads prettyPhoto scripts
        add_action( 'get_header', 'prettyPhoto_scripts' );
        function prettyPhoto_scripts() {	
            wp_enqueue_script( 'prettyPhoto-min', CHILD_URL.'/lib/prettyPhoto/js/jquery-1.6.1.min.js' );
            wp_enqueue_style( 'prettyPhoto-css', CHILD_URL.'/lib/prettyPhoto/css/prettyPhoto.css' );
            wp_enqueue_script( 'prettyPhoto-js', CHILD_URL.'/lib/prettyPhoto/js/jquery.prettyPhoto.js' );
        }
        
        // Adds javascript below footer
        add_action( 'genesis_after_footer', 'prettyPhoto_javascript' );
        function prettyPhoto_javascript() { ?>
        	<script type="text/javascript" charset="utf-8">
        	  $(document).ready(function(){
        	    $("a[rel^='prettyPhoto']").prettyPhoto();
        	  });
        	</script>
        <?php
        }
        		
        // Force layout to full-width-content
        add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' );
        
        // Adds "portfolio" and "gallery clearfix" classes to every post
        add_filter( 'post_class', 'portfolio_post_class' );
        function portfolio_post_class( $classes ) {
            $classes[] = 'portfolio';
            $classes[] = 'gallery clearfix';
            return $classes;
        }
        
        add_filter( 'excerpt_more', 'portfolio_read_more_link' );
        add_filter( 'get_the_content_more_link', 'portfolio_read_more_link' );
        add_filter( 'the_content_more_link', 'portfolio_read_more_link' );
        /**
         * Custom Read More link.
         */
        	function portfolio_read_more_link() {
        		return '<a class="more-link" href="' . get_permalink() . '" rel="nofollow">Read More</a>';
        }
        
        // Remove post info and meta info
        remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
        remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
        
        /**
         * Adds Featured Image and links it to the Post
         */
        function epik_portfolio_do_post_image() { 
        	$img = genesis_get_image( array( 'format' => 'html', 'size' => 'portfolio-thumbnail', 'attr' => array( 'class' => 'alignnone post-image' ) ) ); printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), $img ); 
        }	
        add_action( 'genesis_entry_header', 'epik_portfolio_do_post_image' ); 
        
        // Move title below post image
        remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
        add_action( 'genesis_entry_content', 'genesis_do_post_title', 9 );
        
        // Add Content for the Portfolio posts in this Page Template
        function epik_portfolio_do_post_content() {
            
            if ( genesis_get_option( 'epik_portfolio_content' ) == 'excerpts' ) {
                the_excerpt();
            
            } else {
                if ( genesis_get_option( 'epik_portfolio_content_archive_limit' ) )
                    the_content_limit( (int)genesis_get_option( 'epik_portfolio_content_archive_limit' ), __( 'Read More', 'epik' ) );
                else
                    the_content(__( 'Read More', 'epik' ));
            }
        }
        add_action( 'my_content_area', 'epik_portfolio_do_post_content' );
        
        // Clear float using genesis_custom_loop() $loop_counter variable
        // Outputs clearing div after every 4 posts
        // $loop_counter is incremented after this function is run
        function portfolio_after_post() {
            global $loop_counter;
            
            if ( $loop_counter == 3 ) {
                $loop_counter = -1;
                echo '<div class="clear"></div>';
            }
        }
        add_action( 'genesis_entry_footer', 'portfolio_after_post' );
        
        // Add custom loop
        function portfolio_loop() {
            $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
            
            $include = genesis_get_option( 'epik_portfolio_cat' );
            $exclude = genesis_get_option( 'epik_portfolio_cat_exclude' ) ? explode(',', str_replace(' ', '', genesis_get_option( 'epik_portfolio_cat_exclude' ))) : '';
                
            $cf = genesis_get_custom_field( 'query_args' ); // Easter Egg
            $args = array( 'cat' => $include, 'category__not_in' => $exclude, 'showposts' => genesis_get_option( 'epik_portfolio_cat_num' ), 'paged' => $paged);
            $query_args = wp_parse_args($cf, $args);
            
            genesis_custom_loop( $query_args );
        }
        add_action( 'my_service_loop', 'portfolio_loop' );
        
        // Remove 'site-inner' from structural wrap
        add_theme_support( 'genesis-structural-wraps', array( 'header', 'footer-widgets', 'footer' ) );
        
        // Build the page
        get_header();
        do_action( 'my_custom_fields_area' );
        do_action( 'my_service_loop' );
        do_action( 'my_content_area' );
        get_footer();
        #15441
        hoolamonster
        Customer

          Does anyone know why this is not pulling the css classes for the portfolio?

          #15443
          hoolamonster
          Customer

            I love how Ive walked myself through this haha, trouble is im looking at the epik code but using a totally different aproach

            anyhow I wrapped the portfolio loop like this

            // Add custom loop
            function portfolio_loop() {
            	echo '<div class="content"><div class="wrap">';
                $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
                
                $include = genesis_get_option( 'epik_portfolio_cat' );
                $exclude = genesis_get_option( 'epik_portfolio_cat_exclude' ) ? explode(',', str_replace(' ', '', genesis_get_option( 'epik_portfolio_cat_exclude' ))) : '';
                    
                $cf = genesis_get_custom_field( 'query_args' ); // Easter Egg
                $args = array( 'cat' => $include, 'category__not_in' => $exclude, 'showposts' => genesis_get_option( 'epik_portfolio_cat_num' ), 'paged' => $paged);
                $query_args = wp_parse_args($cf, $args);
                
                genesis_custom_loop( $query_args );
            }
            	echo '</div></div>';

            now all is happy in the world!

            #15468
            Eric
            Customer

              You got it working, nice! Do you have a link we can check out?


              I create awesome sites for awesome people! Contact me if interested – ericsanchez1585@gmail.com

              #15472
              hoolamonster
              Customer

                I dont, Im working locally right now but in a weeks time I will come back and post the link, for reference.

                #15479
                Eric
                Customer

                  Ok, Sounds good 🙂


                  I create awesome sites for awesome people! Contact me if interested – ericsanchez1585@gmail.com

                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.