Created
January 4, 2015 11:24
-
-
Save vimes1984/c5c1ae32a2076e31bacc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//add shortcode | |
add_shortcode( 'properties_list', 'list_porperties_func' ); | |
//short code function | |
function list_porperties_func( $atts ) { | |
$a = shortcode_atts( array( | |
'property_type' => '' | |
), $atts ); | |
ob_start(); | |
require_once(plugin_dir_path(__FILE__) ."/templates/shortcode-archive-listings.php"); | |
return ob_get_clean(); | |
} | |
?> | |
//shortcode-archive-listings.php page | |
<?php | |
$property_type = $a['property_type']; | |
?> | |
<?php $i = 0; ?> | |
<?php | |
wp_reset_query(); | |
$property_archive_loop = new WP_Query( array( 'property-type' => $property_type, 'post_type' => 'property', 'posts_per_page' => '-1')); | |
if($property_archive_loop->have_posts()){ | |
while ( $property_archive_loop->have_posts() ) : $property_archive_loop->the_post(); | |
//Post variables | |
$propertyclas = new propertyListings(); | |
$post_id = $property_archive_loop->post->ID; | |
$metaall = get_post_meta( $post_id ); | |
$post_count = $property_archive_loop->post_count; | |
$class_value = $propertyclas->return_class_number($post_count); | |
?> | |
<?php if($i === 0){ ?> | |
<div class="row"> | |
<?php } | |
?> | |
<!-- Row for main content area --> | |
<div class="small-12 large-<?php echo $class_value; ?> columns" role="main"> | |
<article class="property-archive-shortcode" id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<header> | |
<h2 class="archive-title"><?php the_title(); ?></h2> | |
</header> | |
<div class="entry-content"> | |
<img src="<?php echo $metaall["wpcf-property-gallery-image"][0] ?>" alt="<?php the_title(); ?>"> | |
<?php $propertyclas->custom_experct('custom_excerpt_length', 'wpden_more_view'); ?> | |
</div> | |
<hr /> | |
</article> | |
</div> | |
<?php | |
if ($i === 2 || $i === $post_count - 1 ) { | |
# code... | |
$i = 0; | |
echo "</div>"; | |
}else{ | |
$i ++; | |
} | |
endwhile; | |
}//end if else for posts | |
else{ | |
//this only jumps in if no posts where found using the property_type variable.... | |
$adminurl = site_url() . "/wp-admin/edit-tags.php?taxonomy=property-type&post_type=property"; | |
echo "<h2>No properties of that type found.</h2>"; | |
echo "<p>The Correct syntax for the shortcode is </br> <code>[properties_list property_type='PROPERTY_TYPE_SLUG']</code> </br>, A list of property types can be found by clicking the following button:</br> <a target='_blank' href='$adminurl' class='button expand success'>Property types</a></p>"; | |
} | |
?> | |
<?php wp_reset_query(); ?> | |
//Then short code call is done like so: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment