hangar-wp-theme/home.php

116 lines
3.5 KiB
PHP
Raw Normal View History

2021-02-18 14:09:56 +01:00
<?php
/**
* Home Template
*
* This template is loaded when on the home/blog page.
* Es mostren a la home els posts o pages que tinguin marcat el custom field Inici a 1 i s'ordenen pel valor del custom field Ordre, i sino per data publicació.
* @package Hangar
* @subpackage Template
*/
?>
<?php get_header(); ?>
<?php if( is_home( )) : ?>
<?php // show big widget area if homepage and if active ?>
<aside class="hero">
<?php if ( ! dynamic_sidebar( 'secondary-widget-area' ) ) : ?>
<?php endif; // end secondary widget area ?>
</aside>
<?php endif; //end if is_home ?>
2021-02-18 14:09:56 +01:00
<div id="main" class="maingran">
<div id="content" class="indexall">
2021-02-18 14:09:56 +01:00
<?php
global $wpdb; //seleccionem els posts pels camps creats Inici = 1 i ordenem els registres pel valor del camp Ordre (meta_key / meta_value)
2021-02-18 14:09:56 +01:00
$total = "
SELECT *
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta m1 ON wposts.ID = m1.post_id
INNER JOIN $wpdb->postmeta m2 ON wposts.ID = m2.post_id
WHERE (wposts.post_type = 'post' OR wposts.post_type = 'page')
AND m1.meta_key = 'Inici'
AND m1.meta_value = '1'
AND m2.meta_key = 'Ordre_inici'
AND wposts.post_status = 'publish'
2021-02-18 14:09:56 +01:00
GROUP BY ID
ORDER BY CAST( m2.meta_value AS SIGNED ) ASC
2021-02-18 14:09:56 +01:00
";
2021-02-18 14:09:56 +01:00
$totalposts = $wpdb->get_results($total, OBJECT);
$ppp = intval(get_query_var('posts_per_page')); //sçon 11 per la resta de pàgines índex però a la home en volem 12
$ppp = intval(16);
$wp_query->found_posts = count($totalposts);
$wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp);
$on_page = intval(get_query_var('paged'));
if($on_page == 0){ $on_page = 1; }
2021-02-18 14:09:56 +01:00
$offset = ($on_page-1) * $ppp;
2021-02-18 14:09:56 +01:00
$wp_query->request = "SELECT *
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta m1 ON wposts.ID = m1.post_id
INNER JOIN $wpdb->postmeta m2 ON wposts.ID = m2.post_id
WHERE (wposts.post_type = 'post' OR wposts.post_type = 'page')
AND m1.meta_key = 'Inici'
AND m1.meta_value = '1'
AND m2.meta_key = 'Ordre_inici'
AND wposts.post_status = 'publish'
2021-02-18 14:09:56 +01:00
GROUP BY ID
ORDER BY CAST( m2.meta_value AS SIGNED ) ASC
2021-02-18 14:09:56 +01:00
LIMIT $ppp OFFSET $offset";
$pageposts = $wpdb->get_results($wp_query->request, OBJECT);
2021-02-18 14:09:56 +01:00
?>
<?php if ($pageposts): //amb els resultats trobats per la query distingim les categories de les pàgines pq s'han de pintar diferent
global $post;
2021-02-18 14:09:56 +01:00
echo '<ul>';
foreach ($pageposts as $post):
setup_postdata($post);
$category = get_the_category();
if ($category) :
2021-02-18 14:09:56 +01:00
$tipus = 'catt' ;
else:
if (is_page_child($post, 2)) :
$tipus = 'art'; //artistes
elseif (is_page_child($post, 58856)) :
$tipus = 'art'; //artistes
elseif (is_page_child($post, 46565)) :
$tipus = 'art'; //artistes
elseif (is_page_child($post, 46572)) :
$tipus = 'art'; //artistes
2021-02-18 14:09:56 +01:00
elseif (is_page_child($post, 136)) :
$tipus = 'desc'; //descàrregues
2021-02-18 14:09:56 +01:00
elseif (is_page_child($post, 74)) :
$tipus = 'equip'; //equip
elseif (is_page_child($post, 40378)) :
$tipus = 'equip'; //equip
2021-02-18 14:09:56 +01:00
else :
$tipus = 'pag';
endif;
endif;
include(TEMPLATEPATH . "/caixes.php");
2021-02-18 14:09:56 +01:00
endforeach; ?>
</ul>
2021-02-18 14:09:56 +01:00
<?php wp_pagenavi(); ?>
2021-02-18 14:09:56 +01:00
<?php else : ?>
<h2 class="center"><?php _e( 'Not found.', 'hangar' ); ?></h2>
<p class="center"><?php _e( "Sorry, but you are looking for something that isn't here.", 'hangar' ); ?></p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif;
wp_reset_postdata();
?>
</div> <!-- content -->
</div><!-- fi main -->
2021-02-18 14:09:56 +01:00
<?php get_footer(); ?>