Styling Address section in single store page
-
I would like to remove the <span> tags from around the address and contact details section and have more control over the styling of area?
Thanks in advance.
-
FYI, I have already enabled the single-wpsl_stores.php template page.
From this, I can only alter the order of the map, address and hours data via the shortcodes and can’t actually edit the formatting of the text produced by it, like I can with the wpsl_listing_template filter for the listing frontend.
The only way to do that is by writing custom code that outputs the address details.
You can see how the [wpsl_address] creates the HTML output here.
You can copy it, paste it in the single-wpsl_stores.php, and adjust it to your needs. Do replace $atts[‘id’] with $queried_object->ID, and leave out the $atts everywhere.
Ok, not sure I have got the code quite right. This is what I have pasted into single-wpsl_stores.php but when I go to navigate the page, it is broken and returning a 500 error.
<?php if ( get_post_type() == 'wpsl_stores' ) { if ( empty( $queried_object->ID ) ) { if ( isset( $post->ID ) ) { $queried_object->ID = $post->ID; } else { return; } } } else if ( empty( $queried_object->ID ) ) { return __( 'If you use the [wpsl_address] shortcode outside a store page you need to set the ID attribute.', 'wpsl' ); } $content = '<div class="wpsl-locations-details">'; if ( ['name'] && $store_name = get_the_title( $queried_object->ID ) ) { $content .= '<span><strong>' . esc_html( $store_name ) . '</strong></span>'; } $content .= '<div class="wpsl-location-address">'; if ( ['address'] && $store_address = get_post_meta( $queried_object->ID, 'wpsl_address', true ) ) { $content .= '<span>' . esc_html( $store_address ) . '</span><br/>'; } if ( ['address2'] && $store_address2 = get_post_meta( $queried_object->ID, 'wpsl_address2', true ) ) { $content .= '<span>' . esc_html( $store_address2 ) . '</span><br/>'; } $address_format = explode( '_', $wpsl_settings['address_format'] ); $count = count( $address_format ); $i = 1; // Loop over the address parts to make sure they are shown in the right order. foreach ( $address_format as $address_part ) { // Make sure the shortcode attribute is set to true for the $address_part, and it's not the 'comma' part. if ( $address_part != 'comma' && [$address_part] ) { $post_meta = get_post_meta( $queried_object->ID, 'wpsl_' . $address_part, true ); if ( $post_meta ) { /* * Check if the next part of the address is set to 'comma'. * If so add the, after the current address part, otherwise just show a space */ if ( isset( $address_format[$i] ) && ( $address_format[$i] == 'comma' ) ) { $punctuation = ', '; } else { $punctuation = ' '; } // If we have reached the last item add a <br /> behind it. $br = ( $count == $i ) ? '<br />' : ''; $content .= '<span>' . esc_html( $post_meta ) . $punctuation . '</span>' . $br; } } $i++; } if ( ['country'] && $store_country = get_post_meta( $queried_object->ID, 'wpsl_country', true ) ) { $content .= '<span>' . esc_html( $store_country ) . '</span>'; } $content .= '</div>'; ?>
Try this code.
That is still breaking the page for some reason? Without it, the pages works fine. Existing code (minus your suggestion above) shown below:
<?php /** * Example of a single WPSL store template for the Twenty Fifteen theme. * * @package Twenty_Fifteen */ get_header(); ?> <div class="main_bg"> <div id="content" class="row main"> <div class="twelve columns"> <main id="main" class="site-main" role="main"> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title"><?php single_post_title(); ?></h1> </header> <?php global $post; $queried_object = get_queried_object(); // Add the map shortcode echo do_shortcode( '[wpsl_map]' ); ?> </div> <div class="four columns"> <h3>Address</h3> <?php // Added wpsl-custom-address.php code here ?> <h3>Opening Hours</h3> <?php global $post; $queried_object = get_queried_object(); // Add the address shortcode echo do_shortcode( '[wpsl_hours]' ); ?> </div> <div class="eight columns"> <?php global $post; $queried_object = get_queried_object(); // Add the content $post = get_post( $queried_object->ID ); setup_postdata( $post ); the_content(); wp_reset_postdata( $post ); ?> <h3>Contact Dealer</h3> <?php echo do_shortcode('[contact-form-7 id="66" title="Dealer Page Contact Form"]');?> </div> </article> </main><!-- #main --> </div> </div><!-- #primary --> <?php get_footer(); ?>'
Fixed it. Error caused by [] around second reference of $address_part on line 58 of your example. Removed those and it worked.
Thanks for your help Tijmen. Really pleased with this plugin ??
- The topic ‘Styling Address section in single store page’ is closed to new replies.