• Resolved johndoe01

    (@johndoe01)


    Greetings.
    I have a doubt for overriding.
    I have read the documentation to do an override for the single advert as single -advert.php The file goes this way

    <?php get_header(); ?>
    <?php //var_dump($post); ?>
    
    <?php    /* global $wp_query;
        remove_filter("the_content", "adverts_the_content");
        echo shortcode_adverts_list(array(
            "category" => $wp_query->get_queried_object_id()
         ));*/?>
    
    <main id="singular type-page ">
    <article class="block container "id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'entry' ); ?>
    <?php //the_content(); ?>
    <?php /*Test*/ ?>
    <?php 
        $post_id = $post->ID; $post_content = $post->post_content;          
        $currency = get_post_meta( $post_id, "currency", false ); 
        $price = get_post_meta( get_the_ID(), "adverts_price", true );
        $taxes = get_post_meta( $post_id, "taxes", false );
        ?>    
    <?php #var_dump(get_post_meta( $post_id, "taxes", false )); ?>
        <?php //echo esc_html($post_content) ?>
    
        <?php $pricetag = adverts_price($price); 
                $nosign = substr($pricetag,1); ?>
        
        <div class="header container ad">
        <div id="listing-title">
        <h1 class="entry-title"><?php the_title(); ?></h1> <?php edit_post_link(); ?>
        </div>
        <div class="meta ad-title">
            <div class="taxonomy-date">
                <?php
                $year = get_post_meta( $post_id, "year", false );
                if (!empty($year)){
                    echo $year[0];
                }else{
                    echo "Undisclosed Year";
                }
                ?>
                
            </div>
            <div class="taxonomy-condition">
                <?php
                $year = get_post_meta( $post_id, "condition", true );
                if (!empty($condition)){
                    echo $condition[0];
                }else{
                    echo "Unknown Condition";
                }
                ?>            
            </div>
            <div class="taxonomy-location"><?php echo apply_filters( "adverts_tpl_single_location", esc_html( get_post_meta( $post_id, "adverts_location", true ) ), $post_id ) ?></div>
        </div>
        <?php if( get_post_meta( $post_id, "adverts_price", true) ): ?>
    
            <p class="price adverts-price-box">
                <?php if (($taxes[0] == "+ VAT")||($taxes[0] == "Excluding VAT")) :?>
                <?php echo $currency[0]." ".$nosign." 
                <br/>". $taxes[0]; ?>
                <?php else: ?>
                <?php echo $currency[0]." ".$nosign; ?>
                <?php endif; ?>
            </p>
    
        <?php elseif( adverts_config( 'empty_price' ) ): ?>
    
            <p class="price adverts-price-box"><?php echo esc_html( adverts_empty_price( get_the_ID() ) ) ?><?php if (!empty($taxes))
                    {if (($taxes[0] == "+ VAT")||($taxes[0] == "Excluding VAT")) :?>
                    
                    <?php echo " ".$taxes[0]; ?>
     
                    <?php endif;} ?></p>
    
        <?php endif; ?>    
    
        <a class="ad-enquire-scroller button primary" href="javascript:;">Enquire</a>    
    </div>   
    
        
    <div class="main container ad" >
        <div class="layout has-sidebar">
        <div class="main"><?php //the_content(); ?>
            
            <?php
        wp_enqueue_style( 'adverts-frontend' );
        wp_enqueue_style( 'adverts-icons' );
        wp_enqueue_style( 'adverts-icons-animate' );
    
        wp_enqueue_script( 'adverts-frontend' );
        
    ?>
        
            <?php do_action( "adverts_tpl_single_top", $post_id ) ?>
    
    <div class="meta ad-secondary">
        <div class="taxonomy-ad-category">
        <?php /*foreach($advert_category as $c): ?> 
                <a href="<?php echo esc_attr( get_term_link( $c ) ) ?>"><?php echo join( " / ", advert_category_path( $c ) ) ?></a><br/>
                <?php endforeach;*/ ?>
        </div>   
        
        <p class="seller">
        <?php printf( __('Published: %1$s (%2$s ago)', "wpadverts"), date_i18n( get_option( 'date_format' ), get_post_time( 'U', false, $post_id ) ), human_time_diff( get_post_time( 'U', false, $post_id ), current_time('timestamp') ) ) ?> |     
        <?php echo apply_filters( "adverts_tpl_single_posted_by", sprintf( __("Posted by&nbsp; <strong> %s</strong>", "wpadverts"), get_post_meta($post_id, 'adverts_person', true) ), $post_id ) ?>
        </p>    
    </div>
    <div class="adverts-single-box">
        <div class="iconos">
          <?php do_action( "adverts_tpl_single_details", $post_id ) ?>      
        </div>
        
        <?php /*
        <div class="adverts-single-author">
            <div class="adverts-single-author-avatar">
                <?php $id_or_email = get_post_field( 'post_author', $post_id ) ?>
                <?php $id_or_email = $id_or_email ? $id_or_email : get_post_meta($post_id, 'adverts_email', true) ?>
                <?php echo get_avatar( $id_or_email, 48 ) ?>
            </div>  
            <div class="adverts-single-author-name">
                <?php echo apply_filters( "adverts_tpl_single_posted_by", sprintf( __("by <strong>%s</strong>", "wpadverts"), get_post_meta($post_id, 'adverts_person', true) ), $post_id ) ?><br/>
                <?php printf( __('Published: %1$s (%2$s ago)', "wpadverts"), date_i18n( get_option( 'date_format' ), get_post_time( 'U', false, $post_id ) ), human_time_diff( get_post_time( 'U', false, $post_id ), current_time('timestamp') ) ) ?>
            </div>
        </div>*/?>
        
        <?php if( get_post_meta( $post_id, "adverts_price", true) ): ?>
        <div class="adverts-single-price">
            <span class="adverts-price-box">
                <?php #echo esc_html( adverts_get_the_price( $post_id )) ?>
                <?php echo $currency[0]." ".$nosign; ?>
                <?php if (($taxes[0] == "+ VAT")||($taxes[0] == "Excluding VAT")) :?>
                    
                    <?php echo " ".$taxes[0]; ?>
     
                    <?php endif; ?>
            </span>
            
        </div>
        <?php elseif( adverts_config( 'empty_price' ) ): ?>
        <div class="adverts-single-price adverts-price-empty">
            <span class="adverts-price-box"><?php echo esc_html( adverts_empty_price( get_the_ID() ) ) ?>
            <?php if (!empty($taxes))
                    {if (($taxes[0] == "+ VAT")||($taxes[0] == "Excluding VAT")) :?>
                    
                    <?php echo " ".$taxes[0]; ?>
     
                    <?php endif;} ?>
            </span>
            
                    
        </div>
        <?php endif; ?>
    </div> 
    
    <div class="adverts-grid adverts-grid-closed-top adverts-grid-with-icons adverts-single-grid-details">
        <?php $advert_category = get_the_terms( $post_id, 'advert_category' ) ?>
        <?php if(!empty($advert_category)): ?> 
        <div class="adverts-grid-row ">
            <div class="adverts-grid-col adverts-col-30">
                <span class="adverts-round-icon adverts-icon-tags"></span>
                <span class="adverts-row-title"><?php _e("Category", "wpadverts") ?></span>
            </div>
            <div class="adverts-grid-col adverts-col-65">
                <?php foreach($advert_category as $c): ?> 
                <a href="<?php echo esc_attr( get_term_link( $c ) ) ?>"><?php echo join( " / ", advert_category_path( $c ) ) ?></a><br/>
                <?php endforeach; ?>
            </div>
        </div>        
        
        <?php endif; ?>
        
        <table>
            <?php $status = get_post_meta( $post_id, "statuses", false );
                if (!empty($status)) :?>
            <tr>
                <th>Status</th>
                <td><?php echo $status[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $doors = get_post_meta( $post_id, "doors", false );
                if (!empty($doors)) :?>
            <tr>
                <th>Doors</th>
                <td><?php echo $doors[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $fuel = get_post_meta( $post_id, "fuel", false );
                if (!empty($fuel)) :?>
            <tr>
                <th>Fuel</th>
                <td><?php echo $fuel[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $transmission = get_post_meta( $post_id, "transmission", false );
                if (!empty($transmission)) :?>
            <tr>
                <th>Transmission</th>
                <td><?php echo $transmission[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $spares = get_post_meta( $post_id, "spares", false );
                if (!empty($spares)) :?>
            <tr>
                <th>Spares</th>
                <td><?php echo $spares[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $history = get_post_meta( $post_id, "history", false );
                if (!empty($history)) :?>
            <tr>
                <th>Vehicle History</th>
                <td><?php echo $history[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $collection = get_post_meta( $post_id, "collections", false );
                if (!empty($collection)) :?>
            <tr>
                <th>Collection</th>
                <td><?php echo $collection[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php 
                if (!empty($currency)) :?>
            <tr>
                <th>Currency</th>
                <td><?php echo $currency[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php 
                if (!empty($taxes)) :?>
            <tr>
                <th>Taxes Applied</th>
                <td><?php echo $taxes[0];  ?></td>
            </tr>
            <?php endif; ?>
            <?php $payments = get_post_meta( $post_id, "payments", false );
                if (!empty($payments)) :?>
            <tr>
                <th>Payments</th>
                <td><?php echo $payments[0];  ?></td>
            </tr>
            <?php endif; ?>
        </table>
            
        <?php /*if(get_post_meta( $post_id, "adverts_location", true )): ?>
        <div class="adverts-grid-row">
            <div class="adverts-grid-col adverts-col-30">
                <span class="adverts-round-icon adverts-icon-location"></span>
                <span class="adverts-row-title"><?php _e("Location", "wpadverts") ?></span>
            </div>
            <div class="adverts-grid-col adverts-col-65">
                <?php echo apply_filters( "adverts_tpl_single_location", esc_html( get_post_meta( $post_id, "adverts_location", true ) ), $post_id ) ?>
            </div>
        </div>
        <?php endif;*/ ?>
        
        <?php #do_action( "adverts_tpl_single_details", $post_id ) ?>
    </div>
    
    <div class="adverts-content">
        <?php echo $post_content ?>
    </div>
    
    <?php //do_action( "adverts_tpl_single_bottom", $post_id ) ?>
            
        </div>
        <aside class="sidebar">
            <div class="seller-panel">
                <p class="seller-logo">
        
                <?php $id_or_email = get_post_field( 'post_author', $post_id ) ?>
                <?php $id_or_email = $id_or_email ? $id_or_email : get_post_meta($post_id, 'adverts_email', true) ?>
                <?php echo get_avatar( $id_or_email, 48 ) ?>
            
            </p>
            <div class="seller-details">
                <?php do_action( "adverts_tpl_single_bottom", $post_id ) ?></div> 
                <?php /*
    		gravity_form(
    			1,
    			false,
    			false,
    			false,
    			[
    				'seller'       => $seller->post_title,
    				'seller_email' => get_field( 'email', $seller->ID ),
    			],
    			true
    		);*/
    		?>
        
        </div>
        <div class="seller-form item">
            <div class="header">
            <a tabindex="0" class="control">
    			<h2>Contact</h2><span class="control"></span>
    		</a>
            </div>
            <div class="main">
            
                <?php
    		gravity_form(
    			3,
    			false,
    			false,
    			false,
    			false /*array de valores*/,
    			true
    		);
    		?>            
            </div>
        </div>
    <?php    /**
     * Share Links
     *
     * @package theme
     */
    
    $platforms = get_share_data(
    	[
    		'linkedin',
    		'facebook',
    		'twitter',
    	]
    );
    ?>
    <ul class="list social-media share">
    	<li>Share</li>
    	<?php
    	foreach ( $platforms as $platform ) {
    		$attrs = [
    			'href'   => esc_url( $platform['url'] ),
    			'target' => '_blank',
    			'class'  => 'icon-' . $platform['class'],
    		];
    		?>
    		<li class="item">
    			<a <?php the_attr( $attrs ); ?>>
    				<?php echo wp_kses_post( $platform['label'] ); ?>
    			</a>
    		</li>
    		<?php
    	}
    	?>
    </ul>    
            
            Sidebar
            
            </aside>    
        </div>
        
        
        </div>  
    
        
    <?php /*Test*/ ?>
        
        
    <?php if ( comments_open() && ! post_password_required() ) { comments_template( '', true ); } ?>
    <?php endwhile; endif; ?>
        </article>    
    <footer class="footer">
    <?php get_template_part( 'nav', 'below-single' ); ?>
    </footer>
    </main>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    However there is a major difference with $post_content, when is rendered enabling the_content(); what when doing the Layout arrangements. In the following screenshot i placed both options and the block corresponding to the $post_content renders differently. How can i fix that?

    Second and this is strange, i want to try to embed a youtube video but doesnt show either with the default wordpress shortcode or with another plugin. What could try to allow to render such fields?

    Thanks in advance

    View post on imgur.com

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    1. when you are not using the_content() the filters applied by other plugins and themes to content are not being executed, so the first example is displaying only content rendered by WPAdverts while the second example is displaying content modified by other plugins/themes.

    2. the shortcodes in the Ad descriptions are disabled as this would allow anonymous visitors to execute any shortcode on your website.

    If you want to enable them at your own risk then you should be able to do that by adding the code below in your theme functions.php file

    
    add_filter("adverts_the_content", "do_shortcode");
    
    Thread Starter johndoe01

    (@johndoe01)

    Hello. I placed the code in the functions.php of the template but with no changes.
    I was about to post that other difference you haven’t saw was the Paragraphs on the description while with the_content() appears while on the custom layout doesn’t.

    I’ll see if i can find a workaround with that.

    Thread Starter johndoe01

    (@johndoe01)

    Well The issue got partially solved;
    I replaced the echo $content with echo do_shortcode($content); I tested removing the add filter on the functions.php and works as well.

    This works for me in the way that i need a single field with video and i can render it.

    However the paragraphs of the description are inline. I’ll check if i can find out a similar solution.

    Thread Starter johndoe01

    (@johndoe01)

    Finally:

    The shortcode override was the option on the previous answer.

    To recover the paragraphs format you need to set first on the single-advert.php

    $post_id = $post->ID; 
        $post_content = get_post( $post_id )->post_content;
        $post_content = wp_kses($post_content, wp_kses_allowed_html( 'post' ) );
        $post_content = apply_filters( "adverts_the_content", $post_content );

    In the i got a good idea to format what i need . Thanks for the help. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Template override not Behaving Properly’ is closed to new replies.