• Resolved MrWilson2013

    (@mrwilson2013)


    Hello, I’ve tried a few plugins and by far this one seems to be the best one i’ve used.

    I’m having some issue adding what I need though. I want to show the related products using this layout (coming from a working similar products php which works but I cant select manual relation)

    <?php
    if( has_post_thumbnail() ){
    the_post_thumbnail();
    }
    else{
    echo '<img src="'.esc_url( get_template_directory_uri().'/images/product-placeholder.jpg' ).'">';
    }
    ?>
    </div>
    <div>
    <a class="overlay" href="<?php the_permalink() ?>">
    <i class="fa fa-compress"></i>
    <h3><?php _e( 'COMPARE', 'compare' ) ?></h3>
    </a>
    
    <div style="font-size:16px; font-weight:bold;">
    <?php if ( CFS()->get( 'manual_price' ) ){  ?>
    <div class="price-box-cust">
    <?php echo CFS()->get( 'manual_price'); ?>
    </div>
    <?php } else { ?>
    <?php
    $min_price = !empty( $product_metas[get_the_ID()] ) ? $product_metas[get_the_ID()]['minPrice'] : 0;
    echo __( '', 'compare' ).'<div class="price-box-cust">'.compare_format_currency_number( $min_price ).'</div>';
    ?><?php } ?>
    
    </div>
    
    </div>
    
    </div>
    
    <div class="white-block-content">
    <h4>
    <a href="<?php the_permalink() ?>">
    <?php
    $title = get_the_title();
    if( strlen( $title ) > 25 ){
    $title = substr( $title, 0, 25 ).'...';
    }
    echo esc_html( $title );
    ?>
    </a>
    
    </h4>
    <p class="product-ratings">	<?php compare_get_ratings() ?></p>
    
    <div class="myDiv" style="font-weight:bold; padding:0px 0px 5px 0px; color:#900; font-size:13px;"><?php echo CFS()->get( 'price_message' ); ?></div>
    
    </div>

    Would you be a massive help and help me with this? I’ve tried all the ways I know off.

    Many thanks look forward to your reply

    https://wordpress.org/plugins/related/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Hi,
    With CSF I am not familiar, but just following the codex, and using the post_ID for functions brings me to this (untested). Does that help you?

    global $related;
    $rel = $related->show( get_the_ID(), true );
    
    // Display the title of each related post
    if( is_array( $rel ) && count( $rel ) > 0 ) {
    	foreach ( $rel as $r ) {
    		if ( is_object( $r ) ) {
    			if ($r->post_status != 'trash') {
    				?>
    				<div>
    					<?php
    					echo get_the_title( $r->ID ) . '<br />';
    
    					if ( has_post_thumbnail( $r->ID ) ) {
    						echo get_the_post_thumbnail( $r->ID );
    					} else {
    						echo '<img src="'.esc_url( get_template_directory_uri().'/images/product-placeholder.jpg' ).'">';
    					}
    					?>
    				</div>
    				<div>
    					<a class="overlay" href="<?php echo get_permalink( $r->ID ) ?>">
    						<i class="fa fa-compress"></i>
    						<h3><?php _e( 'COMPARE', 'compare' ) ?></h3>
    					</a>
    
    					<div style="font-size:16px; font-weight:bold;">
    						<?php
    						if ( CFS()->get( 'manual_price' ) ){  ?>
    							<div class="price-box-cust">
    								<?php echo CFS()->get( 'manual_price'); ?>
    							</div>
    							<?php
    						} else {
    							$min_price = !empty( $product_metas[get_the_ID()] ) ? $product_metas[get_the_ID()]['minPrice'] : 0;
    							echo __( '', 'compare' ).'<div class="price-box-cust">'.compare_format_currency_number( $min_price ).'</div>';
    						} ?>
    					</div>
    				</div>
    
    				<div class="white-block-content">
    					<h4>
    						<a href="<?php echo get_permalink( $r->ID ) ?>">
    							<?php
    							$title = get_the_title( $r->ID );
    							if( strlen( $title ) > 25 ){
    							$title = substr( $title, 0, 25 ).'...';
    							}
    							echo esc_html( $title );
    							?>
    						</a>
    					</h4>
    					<p class="product-ratings"><?php compare_get_ratings() ?></p>
    
    					<div class="myDiv" style="font-weight:bold; padding:0px 0px 5px 0px; color:#900; font-size:13px;">
    						<?php echo CFS()->get( 'price_message' ); ?>
    					</div>
    
    				</div>
    				<?php
    			}
    		}
    	}
    }
    Thread Starter MrWilson2013

    (@mrwilson2013)

    The layout works perfectly everything is in its correct place.

    2 issues. First the related post I selected doesnt show, The product im currently on shows. (Current post)

    The second issue is, is that the prices will not show. It just sets them to £0.00

    This is the price bit on its own. and this is the plugin im using

    https://wordpress.org/plugins/custom-field-suite/`

    <?php if ( CFS()->get( 'manual_price' ) ){  ?>
    <div class="price-box-cust">
    <?php echo CFS()->get( 'manual_price'); ?>
    </div>
    <?php } else { ?>
    <?php
    $min_price = !empty( $product_metas[get_the_ID()] ) ? $product_metas[get_the_ID()]['minPrice'] : 0;
    echo __( '', 'compare' ).'<div class="price-box-cust">'.compare_format_currency_number( $min_price ).'</div>';
    ?><?php } ?>

    Thread Starter MrWilson2013

    (@mrwilson2013)

    Fixed the first Issue above – Didnt copy it correctly over. I can only add 2 related items before it clones itself.

    http://www.awesomescreenshot.com/image/1285557/904ffcbf7ca3c725016dd62da55a1178

    Plugin Author Marcel Pol

    (@mpol)

    Just looking at that piece of code….

    I don’t know what the last functioncall is from.

    And that it doesn’t loop correctly is a bit strange. Could you run:
    var_dump( $related ); on top after the $related->show() call?

    <?php if ( CFS()->get( 'manual_price', $r->ID ) ){  ?>
    <div class="price-box-cust">
    <?php echo CFS()->get(  'manual_price', $r->ID ); ?>
    </div>
    <?php } else { ?>
    <?php
    $min_price = !empty( $product_metas[ $r->ID ] ) ? $product_metas[ $r->ID]['minPrice'] : 0;
    echo __( '', 'compare' ).'<div class="price-box-cust">'.compare_format_currency_number( $min_price ).'</div>';
    ?><?php } ?>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding information and layout.’ is closed to new replies.