wordpress get_terms and WP_Query not working as expected - php

i've created a colophon for my website in which i post all the logos of the different sponsors i have. I add all the sponsors via custom post type. i also added a specific custom taxonomy to distinguish between the different typologies of sponsorships.
I use this code in the footer.php to display them:
<?php $terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { ?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $term->slug,
);
$pesca_post = new WP_Query ($arg);
$quanti_post = $pesca_post->post_count;
if(have_posts()){
while ($pesca_post->have_posts()) : $pesca_post->the_post();
$featured = get_the_post_thumbnail_url(get_the_ID(),'large');
if ($quanti_post == 5){
$classe_bootstrap = 15;
}elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
echo '<div class="col-md-' . $classe_bootstrap . '">';
if (isset($featured)){
$img = $featured;
}else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($post->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
<?php echo '</div>';
endwhile;
}?>
</div>
<?php }
}?>
my problem is that this code is completely working just on some pages, on other it shows the contents avoiding the ones belonging to the first term, no matter which it will be.
I have noticed that it works in pagaes where i use other queries.
What am i doing wrong?

i changed it in this way and now it's working!
$terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { //per ogni termine presente
$nome = $term->slug;?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $nome,
);
$elementi = get_posts($arg);
$quanti_post = count( $elementi );
if ($quanti_post == 5){
$classe_bootstrap = 15;
}
elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}
elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
foreach($elementi as $elemento){
$featured = get_the_post_thumbnail_url($elemento->ID,'large');
if (isset($featured)){
$img = $featured;
}
else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<div class="col-md-<?php echo $classe_bootstrap; ?>">
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($elemento->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
</div>
<?php }?>
</div>
<?php }
}?>

Related

Change the profile cover image dynamically

does someone know how to change an image header dynamically depends by specific categories,
ex: image1 for red category, image2 for blue category, image3 for green category?
Im using ultimate member plugin but don't well php coding
I have found the original code
function um_profile_header_cover_area( $args ) {
global $ultimatemember;
if ( $args['cover_enabled'] == 1 ) {
$default_cover = um_get_option('default_cover');
$overlay = '<span class="um-cover-overlay">
<span class="um-cover-overlay-s">
<ins>
<i class="um-faicon-picture-o"></i>
<span class="um-cover-overlay-t">'.__('Change your cover photo', 'ultimatemember').'</span>
</ins>
</span>
</span>';
?>
<div class="um-cover <?php if ( um_profile('cover_photo') || ( $default_cover && $default_cover['url'] ) ) echo 'has-cover'; ?>" data-user_id="<?php echo um_profile_id(); ?>" data-ratio="<?php echo $args['cover_ratio']; ?>">
<?php do_action('um_cover_area_content', um_profile_id() ); ?>
<?php
if ( $ultimatemember->fields->editing ) {
$items = array(
''.__('Change cover photo', 'ultimatemember').'',
''.__('Remove', 'ultimatemember').'',
''.__('Cancel', 'ultimatemember').'',
);
echo $ultimatemember->menu->new_ui( 'bc', 'div.um-cover', 'click', $items );
}
?>
<?php $ultimatemember->fields->add_hidden_field( 'cover_photo' ); ?>
<?php echo $overlay; ?>
<div class="um-cover-e">
<?php if ( um_profile('cover_photo') ) { ?>
<?php
if( $ultimatemember->mobile->isMobile() ) {
if ( $ultimatemember->mobile->isTablet() ) {
echo um_user('cover_photo', 1000);
echo um_user('cover_photo', 300);
}
} else {
echo um_user('cover_photo', 1000);
}
?>
<?php } elseif ( $default_cover && $default_cover['url'] ) {
$default_cover = $default_cover['url'];
echo '<img src="'. $default_cover . '" alt="" />';
} else {
if ( !isset( $ultimatemember->user->cannot_edit ) ) { ?>
<span class="um-cover-add-i"><i class="um-icon-plus um-tip-n" title="<?php _e('Upload a cover photo', 'ultimatemember'); ?>"></i></span>
<?php }
} ?>
</div></div>
<?php
}}
Thanks in advance

Cannot redeclare function error in for each

I am attempting to pull information from a custom post, feed it into a foreach loop and then echo it out into a function in repeating panel. At some point I'm guessing the function declaration is being redeclared (it is not in any other file, I'm 100% confident of this) as I keep getting a "Cannot redeclare output_member() previously declared in same file path php 43".
Any help is appreciated.
function output_team_members( $title, $id, $position ) {
$post_thumbnail = has_post_thumbnail( $id );
if ( $post_thumbnail == true ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='is-active orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</figure>
</li>";
}
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
/** Grabs information about the post types team-member */
function output_member( $team_members ) {
foreach ( $team_members as $member ) {
output_team_members( $member->post_title, $member->ID, $member->post_content );
}
}
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container">
<?php output_member( $team_members ); ?>
</div>
</div>
</div>
I ended up figuring it out. For future devs it was easier to remove the functions all together and just do this
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container" style="height: 500px;">
<?php
foreach ( $team_members as $member ) {
$title = $member->post_title;
$id = $member->ID;
$positon = $member->post_content;
$post_thumbnail = has_post_thumbnail( $id );
if ( true === $post_thumbnail ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
</div>
</figure>
</li>";
}
?>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</div>

How to access ACF fields for a custom post type using 'wpdb'?

I have two WordPress installs, one is to be used as an intranet and the other is public. I need to pull in the data for a custom post type from the public site to be shown on the intranet, essentially so the admin doesn't need to enter the same data on each site.
So, far I've got this:
$wpdb = new wpdb(*CONNECTION DETAILS*);
$careers = $wpdb->get_results(
'SELECT *
FROM wp_posts
WHERE post_type = "career-post"'
);
if (!empty($careers)) {
echo '<ul id="careers-list">';
foreach ($careers as $career) {
echo '<li class="career">';
echo '<a class="wrap" href="http://domainname.com/career/'.$career->post_name.'" target="_blank">';
echo '<h2>'.$career->post_title.'</h2>';
echo get_field('career_duration') ? '<p class="duration">('.get_field('career_duration').')</p>' : '<p class="duration">(permanent)</p>';
echo '<h3>'.get_field('career_area').'</h3>';
echo '<p class="description">'.get_field('career_short_description').'</p>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
Which is pulling in the slug and title as expected, but as the ACF data is stored in a different table, I am not sure how to a) access that data and b) link it to the correct post.
Fetch ACF fields for a custom post type
<?php
$wpdb = new wpdb(*CONNECTION DETAILS*);
$careers = $wpdb->get_results(
'SELECT *
FROM wp_posts
WHERE post_type = "career-post"'
);
if (!empty($careers)) {
?>
<ul id="careers-list">
<?php
foreach ($careers as $career) {
$career_duration = get_field('career_duration', $career->ID);
$career_area = get_field('career_area', $career->ID);
$career_short_description = get_field('career_short_description', $career->ID);
?>
<li class="career">
<a href="<?php echo get_permalink($career->ID); ?>" target="_blank">
<h2><?php echo get_the_title( $career->ID ); ?></h2>
<?php
if($career_duration!="")
{
?>
<p class="duration"><?php echo $career_duration;?></p>
<?php
}
else
{
?>
<p class="duration">permanent</p>
<?php
}
?>
<h3><?php echo $career_area;?></h3>
<p class="description"><?php echo $career_short_description;?></p>
</a>
</li>
<?php
}
?>
</ul>
<?php
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
?>
OR
<?php
$career_post_type = 'career-post';
$career_post_args=array(
'type' => $career_post_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => -1,
'orderby' => 'name',
'order' => 'ASC',
);
$career_post_my_query = null;
$career_post_my_query = new WP_Query($career_post_args);
if( $career_post_my_query->have_posts() )
{
?>
<ul id="careers-list">
<?php
while ($career_post_my_query->have_posts()) : $career_post_my_query->the_post();
$career_duration = get_field('career_duration', $post->ID);
$career_area = get_field('career_area', $post->ID);
$career_short_description = get_field('career_short_description', $post->ID);
?>
<li class="career">
<a href="<?php echo get_permalink($post->ID); ?>" target="_blank">
<h2><?php echo get_the_title( $post->ID ); ?></h2>
<?php
if($career_duration!="")
{
?>
<p class="duration"><?php echo $career_duration;?></p>
<?php
}
else
{
?>
<p class="duration">permanent</p>
<?php
}
?>
<h3><?php echo $career_area;?></h3>
<p class="description"><?php echo $career_short_description;?></p>
</a>
</li>
<?php
endwhile;
?>
</ul>
<?php
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
wp_reset_query($career_post_my_query);
?>
Shital, I don't see how your second solution would work as it's not referencing the external DB?
I've tried the following (similar to your first solution) and it doesn't return anything for the ACF fields either:
foreach ($careers as $career) {
$ID = $career->ID;
$slug = $career->post_name;
$title = $career->post_title;
$duration = get_field('career_duration', $ID);
$area = get_field('career_area', $ID);
$description = get_field('career_short_description', $ID);
echo '<li class="career">';
echo '<a class="wrap" href="http://domainname.com/career/'.$slug.'" target="_blank">';
echo '<h2>'.$title.'</h2>';
echo $duration ? '<p class="duration">('.$duration.')</p>' : '<p class="duration">(permanent)</p>';
echo '<h3>'.$area.'</h3>';
echo '<p class="description">'.$description.'</p>';
echo '</a>';
echo '</li>';
}

Calling PHP function doesn't work in index.php

I have a function I wrote in my functions.php page for a gallery to display on certain pages. It displays on custom templates, but now I need it to display on index.php Here is the code from my functions.php file:
function min_get_page_gallery( $echo = true) {
global $post;
$show_gallery = get_post_meta($post->ID, 'min_gallery-show', true);
if ( empty($show_gallery) ) {
return;
}
$gallery = get_post_meta($post->ID, 'min_image_advanced', false);
ob_start();
?>
<div class="gallery" id="gallery-<?php echo $post->ID; ?>">
<button class="gallery-move-left"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></button>
<div class="image_container clearfix">
<?php
$count = count($gallery);
$num = ceil($count / 3);
//$width_container = $num * 100;
//$width_row = 100 / $num;
//echo '<div class="gallery_inner" style="width:' . $width_container . '%;">';
echo '<div class="gallery_inner">';
for ( $i = 0; $i < $count; $i++) {
if ( $i % 3 == 0 ) {
//echo '<div class="row" style="width: ' . $width_row . '%;">';
echo '<div class="row'. (0 == $i ? ' active': ' inactive') .'">';
}
echo '<div class="col-sm-4 img_container' . (0 == $i ? ' active': ' inactive') . '">';
echo wp_get_attachment_image($gallery[$i], 'thumb-gallery');
echo '</div>';
if ( $i % 3 == 2 || ($i+1) == $count) {
echo '</div>';
}
}
echo '</div>';
?>
</div>
<button class="gallery-move-right"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i></button>
</div>
<?php
$return = ob_get_contents();
ob_end_clean();
if ( $echo ) {
echo $return;
} else {
return $return;
}
}
That code works like a charm. Here is where I call it as min_get_page_gallery(); in awards.php where it works flawlessly:
<?php
/* Template Name: Awards Page Template */
get_header(); ?>
<div class="container" id="block-no-sidebar">
<h1><?php the_title(); ?></h1>
<div id="award-list">
<?php echo min_get_awards(); ?>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
<?php min_get_page_tabs(); ?>
</div>
<?php get_footer(); ?>
Now finally, I try to add the same function call of min_get_page_gallery(); in my index.php file like this:
<?php
// Silence is golden.
if ( ! defined ( 'ABSPATH' ) ) {
exit;
}
?>
<?php get_header(); ?>
<style class="take-to-head">
#block-main-content-with-sidebar { background: #ffffff; }
</style>
<div class="container" id="block-main-content-with-sidebar">
<div class="row">
<div class="col-sm-8">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
l('block-' . get_post_type());
endwhile; else:
l('block-none' );
endif;
?>
</div>
<div class="col-sm-4">
<?php l('block-sidebar'); ?>
</div>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
</div>
Is there something I'm missing??
Try to describe in more detail, what is wrong with your index.php? Is some output when load input.php, or blank page?
Is correctly defined ABSPATH? If not, your script exit on the beginning.
For more specific awareness of flow through the script, try to write there some echo
E.g.
<div class="row">
<?php echo "Before calling min_get_page_gallery()" ?>
<?php min_get_page_gallery(); ?>
<?php echo "After calling min_get_page_gallery()" ?>
</div>
Then look, if you can see the messages from echo before and after calling the desired function.
Ok, so I had to do some tweaking to get the meta to show in functions.php I added these lines:
$pagemain = is_page();
and then:
if ( $pagemain == is_page( 35393 ) ) {
$meta[] = array(
'id' => 'imageupload',
'post_types' => array( 'page'),
'context' => 'normal',
'priority' => 'high',
'title' => __( 'Image Gallery', 'min' ),
'fields' => array(
array(
'name' => __( 'Show', 'min' ),
'id' => "{$prefix}_gallery-show",
'desc' => __( '', 'meta-box' ),
'type' => 'checkbox',
'clone' => false,
),
array(
'id' => "{$prefix}_image_advanced",
'name' => __( 'Image Advanced', 'min' ),
'type' => 'image_advanced',
// Delete image from Media Library when remove it from post meta?
// Note: it might affect other posts if you use same image for multiple posts
'force_delete' => false,
// Maximum image uploads
//'max_file_uploads' => 2,
),
),
);
}

How do I make new posts show on map?

My map shows results from posts, but only old ones. Why aren't new ones showing up? I hired a coder from India but he is hiding now. (I already paid him because I didn't anticipate this bug.)
At the bottom of the map, it says: Total Geocoded Ads: 602. This is not true. There are now 608 published posts. So why aren't new ones being found?
Also, why aren't they being presented in order of post_date?
add_action('wp_ajax_query_total', 'query_total');
add_action('wp_ajax_nopriv_query_total', 'query_total');
if (defined('MULTISITE') && (MULTISITE))
{
if (!defined('TT'))
define('TT', plugins_url('/geo-ads/timthumb_wpmu.php'));
}
else
{
if (!defined('TT'))
define('TT', plugins_url('/geo-ads/timthumb.php'));
}
function query_total()
{
global $wpdb;
$table = $wpdb->prefix.'cp_ad_geocodes';
$q = "SELECT COUNT(*) FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id) WHERE p.post_status = 'publish'";
$c = $wpdb->get_var($q);
echo $c;
die();
}
function query_geo_ads()
{
if ($_GET['range'] == 'true') {
query_geo_ads_refresh();
}
else {
global $wpdb;
$table = $wpdb->prefix.'cp_ad_geocodes';
$querystr = "SELECT t.post_id, t.category, t.lat, t.lng, p.post_title, p.post_content, m.meta_value as price, CONCAT(wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE(wpo.option_value,'%year%',date_format(p.post_date,'%Y')) ,'%monthnum%',date_format(p.post_date,'%m')) ,'%day%',date_format(p.post_date,'%d')) ,'%postname%',p.post_name ) ) as permalink
FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id)
INNER JOIN $wpdb->options wpo ON wpo.option_name='permalink_structure'
INNER JOIN $wpdb->options wpo_su ON wpo_su.option_name='siteurl'
LEFT JOIN $wpdb->postmeta m ON (m.meta_key = 'cp_price') AND (m.post_id = p.ID)
WHERE p.post_status = 'publish'
AND p.post_type = 'ad_listing' ";
$ads = $wpdb->get_results($querystr);
$expires = 50000;
$cache_time = mktime();
header("Cache-Control: max-age:" . $expires . ", must-revalidate");
header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");
echo json_encode($ads);
die();
}
}
function get_image_url()
{ $post_id = intval($_POST['id']);
$attachment = get_posts(array('post_type' => 'attachment','post_status' => 'publish','order' => 'ASC','orderby' => 'post_date','post_mime_type' => 'image','post_parent' => $post_id));
$height = 100;
$width = 100;
$url = TT.'?src='.wp_get_attachment_url($attachment[0]->ID, false).'&h='.$height.'&w='.$width;
if ($attachment)
echo $url;
die();
}
function query_geo_ads_refresh() {
?>
<div class="undertab"><span class="big">Classified Ads / <strong><span class="colour">Just Listed</span></strong></span></div>
<?php
global $wpdb,$wp_query, $post;
$exclude_categories = $_REQUEST['exclude_categories'];
$term_id = $_REQUEST['term_id'];
$term_slug = $_REQUEST['term_slug'];
$taxonomy_name = $_REQUEST['taxonomy_name'];
$northeast_lng = $_REQUEST['northeast_lng'];
$northeast_lat = $_REQUEST['northeast_lat'];
$southwest_lng = $_REQUEST['southwest_lng'];
$southwest_lat = $_REQUEST['southwest_lat'];
if(!empty($exclude_categories)) {
$exclude_categories = explode(';', $exclude_categories);
}
if(!$term_id) // this means root
//$term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0' );
$term_categories = get_terms( 'ad_cat', 'order=DESC','orderby=post_date' );
else {
$current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
$term_categories = get_terms( $taxonomy_name, 'order=DESC','orderby=post_date' );
if(empty($term_categories))
$term_categories[] = $current_term;
}
foreach ($term_categories as $catinfo_obj)
{
$term_id = $catinfo_obj->term_id;
$arrsrch = array("'");
$arrrep = array('');
$name = htmlspecialchars_decode($catinfo_obj->name);
$name = strtolower(str_replace($arrsrch,$arrrep,$name));
if(!empty($exclude_categories)) {
if(in_array(strtolower($name), $exclude_categories))
continue;
}
$subterm_ids = get_term_children( $term_id, 'ad_cat' );
$subterm_ids[] = $term_id;
$term_ids = implode(',', $subterm_ids);
if($term_id)
{
$my_post_type = "'ad_listing'";
$sql = "select * from $wpdb->posts p where p.post_type in ($my_post_type) and p.post_status in ('publish') and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($term_ids) )";
$postinfo = $wpdb->get_results($sql);
$data_arr = array();
$geo_codes = array();
if($postinfo)
{
$srcharr = array("'");
$replarr = array("\'");
foreach($postinfo as $postinfo_obj)
{
$ID = $postinfo_obj->ID;
$title = str_replace($srcharr,$replarr,($postinfo_obj->post_title));
$plink = get_permalink($postinfo_obj->ID);
$geocode = cp_get_geocode($ID);
$lat = $geocode['lat'];
$lng = $geocode['lng'];
// check current post geo place is within map coord area
if($lat > $northeast_lat || $lat < $southwest_lat)
continue;
if($northeast_lng > $southwest_lng) {
if($lng > $northeast_lng || $lng < $southwest_lng)
continue;
} else {
if($lng > 0 && $lng < $southwest_lng)
continue;
if($lng < 0 && $lng > $northeast_lng)
continue;
}
$address = get_post_meta($ID,'cp_address_line',true);
if(!empty($address))
$address = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_address_line',true)));
else {
$street = get_post_meta($ID,'cp_street',true);
$city = get_post_meta($ID,'cp_city',true);
$state = get_post_meta($ID,'cp_state',true);
$country = get_post_meta($ID,'cp_country',true);
if(!empty($street))
$address .= $street . ', ';
if(!empty($city))
$address .= $city . ', ';
if(!empty($state))
$address .= $state . ', ';
if(!empty($country))
$address .= $country . ', ';
$address = trim($address);
$address = substr($address, 0, strlen($address)-1);
$address = str_replace($srcharr,$replarr,$address);
}
$phone = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_phone',true)));
$email = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_email',true)));
$author = get_userdata($postinfo_obj->post_author);
$category = get_the_category($postinfo_obj->ID);
if($postinfo_obj->post_type == 'ad_listing') {
$timing = date('M d, Y',strtotime(get_post_meta($ID,'cp_start_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'cp_end_date',true)));
} else {
$timing = date('M d, Y',strtotime(get_post_meta($ID,'st_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'end_date',true))).'<br />'.get_post_meta($ID,'st_time',true).' to '.get_post_meta($ID,'end_time',true);
}
?>
<?php appthemes_before_post(); ?>
<div class="post-block-out">
<div class="post-block">
<div class="post-left">
<?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail($ID); ?>
</div>
<div class="<?php if ( get_option('cp_ad_images') == 'yes' ) echo 'post-right'; else echo 'post-right-no-img'; ?> <?php echo get_option('cp_ad_right_class'); ?>">
<!-- <h3><?php if ( mb_strlen( $title ) >= 75 ) echo mb_substr( $title, 0, 75 ).'...'; else echo $title; ?></h3>
<div class="clr"></div>
<p class="post-meta">
<span class="folder">
<a href="/ad-category/<?php echo $catinfo_obj->slug; ?>/">
<?php echo $name; ?>
</a>
</span> |
<span class="owner">
<a href="/author/<?php echo $author->user_nicename; ?>">
<?php echo $author->display_name; ?>
</a>
</span> |
<span class="clock"><span><?php echo $timing; ?></span></span>
</p>-->
</div>
<div class="clr"></div>
</div><!-- /post-block -->
</div><!-- /post-block-out -->
<?php
}
}
}
}
die();
}
?>
This is the index.php home page file. This is how the home page appears:
<?php get_header(); ?>
<div class="content_botbg">
<div class="content_res">
<?php // Comment the default CP Slider
// if ( file_exists(STYLESHEETPATH . '/featured.php') )
// include_once(STYLESHEETPATH . '/featured.php');
// else
// include_once(TEMPLATEPATH . '/featured.php');
?>
<!-- left block -->
<!--<div class="content_left">-->
<?php if ( get_option('cp_home_layout') == 'directory' ) : ?>
<div class="shadowblock_out">
<div class="shadowblock">
<h2 class="dotted"><?php _e('Ad Categories','appthemes')?></h2>
<div id="directory" class="directory twoCol">
<?php echo cp_create_categories_list( 'dir' ); ?>
<div class="clr"></div>
</div><!--/directory-->
</div><!-- /shadowblock -->
</div><!-- /shadowblock_out -->
<?php endif; ?>
<div class="tabcontrol">
<ul class="tabnavig">
<li><span class="big"><?php _e('Just Listed','appthemes')?></span></li>
<li><span class="big"><?php _e('Most Popular','appthemes')?></span></li>
<li><span class="big"><?php _e('Random','appthemes')?></span></li>
</ul>
<?php remove_action( 'appthemes_after_endwhile', 'cp_do_pagination' ); ?>
<?php $post_type_url = get_bloginfo('url').'/'.get_option('cp_post_type_permalink').'/'; ?>
<!-- tab 1 -->
<div id="block1">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Just Listed','appthemes') ?></span></strong></span></div>
<?php
// show all ads but make sure the sticky featured ads don't show up first
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array('post_type' => APP_POST_TYPE, 'ignore_sticky_posts' => 1, 'paged' => $paged) );
global $wp_query;
$total_pages = max( 1, absint( $wp_query->max_num_pages ) );
?>
<?php //get_template_part( 'loop', 'ad_listing' ); ?>
<?php
if( $total_pages > 1 ){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
</div><!-- /block1 -->
<!-- tab 2 -->
<div id="block2">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Most Popular','appthemes') ?></span></strong></span></div>
<?php get_template_part( 'loop', 'featured' ); ?>
<?php global $cp_has_next_page; ?>
<?php if($cp_has_next_page){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
<?php wp_reset_query(); ?>
</div><!-- /block2 -->
<!-- tab 3 -->
<div id="block3">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Random','appthemes') ?></span></strong></span></div>
<?php
// show all random ads but make sure the sticky featured ads don't show up first
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array('post_type' => APP_POST_TYPE, 'ignore_sticky_posts' => 1, 'paged' => $paged, 'orderby' => 'rand') );
global $wp_query;
$total_pages = max( 1, absint( $wp_query->max_num_pages ) );
?>
<?php get_template_part( 'loop', 'ad_listing' ); ?>
<?php
if( $total_pages > 1 ){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
</div><!-- /block3 -->
</div><!-- /tabcontrol -->
</div><!-- /content_left -->
<?php //get_sidebar(); ?>
<div class="clr"></div>
</div><!-- /content_res -->
</div><!-- /content_botbg -->

Categories