-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·3842 lines (2943 loc) · 134 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
function google_jquery() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, '1.7.1');
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'google_jquery');
//Attributes for Custom Image Sizes (To use for the Home Slide)
if (function_exists('add_theme_support')){
add_theme_support('post-thumbnails');
}
function add_slider_imgsize(){
if (function_exists('add_image_size')){
add_image_size('new-slide-img', 700, 337, true);
add_image_size('last_event-img', 90, 90, true);
}
}
add_action('admin_init', 'add_slider_imgsize');
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
//Función para desactivar la Toolbar de BuddyPress
if(!current_user_can('editor') && !current_user_can('administrator') && !current_user_can('author')){
define( "BP_DISABLE_ADMIN_BAR", true );
}
//Función para que los autores puedan crear y editar categorías
function noletia_add_theme_caps() {
$role = get_role( 'author' ); // gets the author role
$role->add_cap( 'manage_categories' ); // would allow the author to edit others' posts for current theme only
}
add_action( 'admin_init', 'noletia_add_theme_caps');
// Añadimos el flitro para que ahora, en las búsquedas por defecto,
//añada los tipos que le hemos definido en la función anterior.
add_filter( 'the_search_query', 'searchAll' );
//Función para devolver un numero determinado de caracteres de la cadena dada
function the_excerpt_max_charlength($string, $charlength) {
$excerpt = $string;
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
//Personalización de la función de comentarios
if ( !function_exists( 'bp_dtheme_comment_form' ) ) :
function bp_dtheme_comment_form( $default_labels ) {
global $user_identity;
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'buddypress' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label> ' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'buddypress' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label> ' .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website', 'buddypress' ) . '</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
$new_labels = array(
'comment_field' => '<p class="form-textarea"><textarea name="comment" id="comment" cols="60" rows="10" aria-required="true"></textarea></p>',
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'logged_in_as' => '',
'must_log_in' => '<p class="alert">Debes <a href="'.get_bloginfo('home').'/registro/?redirect_to='.get_permalink().'">identificarte</a> para dejar un comentario.</p>',
'title_reply' => __( 'Leave a reply', 'buddypress' )
);
return apply_filters( 'bp_dtheme_comment_form', array_merge( $default_labels, $new_labels ) );
}
add_filter( 'comment_form_defaults', 'bp_dtheme_comment_form', 10 );
endif;
/***********************************************************************************************************/
//**** FUNCIÓN PARA MOSTRAR EL ENLACE DE "Ver todas las noticias" dependiendo de la portada y de la provincia ******//
/***********************************************************************************************************/
function mostrar_enlace_ver_todas_noticias($tipo_portada){
$provincia = $_COOKIE['noletia_prov'];
$prov_id = get_category_id($provincia);
$tipo_id = get_category_id_from_slug($tipo_portada);
$tipo_name = get_category_name_from_slug($tipo_portada);
echo '<p class="ver_todas_noticias">';
if($tipo_portada == 'descuentos' || $tipo_portada == 'concursos'){
?>
<a href="<?php bloginfo('home'); ?>/events/categories/<?php echo $tipo_portada; ?>/">Ver <?php if($tipo_portada == 'concursos' || $tipo_portada == 'descuentos'){ echo 'todos los '.$tipo_portada; } ?> →</a>
<?php
}elseif( $tipo_portada == 'global'){
if($provincia == '' || $provincia == 'todas'): ?>
<a href="<?php bloginfo('home'); ?>/?s=&x=0&y=0">Ver todas las noticias →</a>
<?php else: ?>
<a href="<?php bloginfo('home'); ?>/categories/<?php echo $prov_id;?>/search_type/and/order/default/">Ver <?php if($tipo_portada == 'concursos' || $tipo_portada == 'descuentos'){ echo 'todos los '.$tipo_portada; }else{ echo 'todas las noticias '; } echo 'de '.$provincia; ?> →</a>
<?php endif;
}else{
if($provincia == '' || $provincia == 'todas'): ?>
<a href="<?php bloginfo('home'); ?>/categories/<?php echo $tipo_id;?>/search_type/and/order/default/">Ver <?php if($tipo_portada == 'concursos' || $tipo_portada == 'descuentos'){ echo 'todos los '.$tipo_portada; }else{ echo 'todas las noticias '; } if($tipo_name != ''){ echo 'de '.$tipo_name;} ?> →</a>
<?php else: ?>
<a href="<?php bloginfo('home'); ?>/categories/<?php if($tipo_id != ''){ echo $tipo_id.','; } echo $prov_id;?>/search_type/and/order/default/">Ver <?php if($tipo_portada == 'concursos' || $tipo_portada == 'descuentos'){ echo 'todos los '.$tipo_portada; }else{ echo 'todas las noticias '; } if($tipo_name != ''){ echo 'de '.$tipo_name;} echo ' en '.$provincia; ?> →</a>
<?php endif;
}
echo '</p>';
}
/***********************************************************************************************************/
//**** COOKIES ******//
/***********************************************************************************************************/
//Función para crear las cookies
function set_noletia_prov_cookie() {
global $wpdb, $current_user;
get_currentuserinfo();
$location = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
if(isset($_POST['header-provincia'])) {
//Si han cambiado el selector de provincia de la cabecera, aumentamos en 1 el contador de esa provincia
$contador = get_option('noletia_estadisticas_select_cont_provincia_'.$_POST['header-provincia'],0);
$contador++;
update_option('noletia_estadisticas_select_cont_provincia_'.$_POST['header-provincia'], $contador);
//Fin del código del contador de "changes" en el selector
//Cada vez que alguien cambia el selector de provincia de la cabecera se aade un nuevo campo a la tabla: estadisticas_selector_prov
date_default_timezone_set('Europe/Madrid');
$prov = $_POST['header-provincia'];
$usu = $current_user->user_login;
$fecha = date('Y-m-d H:i');
$wpdb->query("INSERT INTO estadisticas_selector_prov(provincia, usuario, fecha) VALUES('".$prov."','".$usu."','".$fecha."')");
//Fin estadisticas_selector_prov
if(!isset($_COOKIE['noletia_prov'])){
setcookie('noletia_prov', $_POST['header-provincia'], time()+1209600, "/", COOKIE_DOMAIN, false, false);
wp_redirect( $location);
exit;
}else{
setcookie('noletia_prov', "", time()-360);
setcookie('noletia_prov', $_POST['header-provincia'], time()+1209600, "/", COOKIE_DOMAIN, false, false);
wp_redirect( $location);
exit;
}
}
}
add_action( 'init', 'set_noletia_prov_cookie');
//PANEL DE ADMINISTRACIÓN: GESTOR DE PORTADAS
//Función para crear las cookies para el gestor de portadas del panel de administración. Campo Provincia
function set_noletia_gestor_portadas_cookie() {
$location = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
if(isset($_POST['noletia_ver_portada'])){
if(isset($_POST['noletia_portadas_prov']) || isset($_POST['noletia_portadas_tipo'])){
setcookie('noletia_gest_port_tipo_prov', $_POST['noletia_portadas_tipo'].'---'.$_POST['noletia_portadas_prov'], time()+1080, "/", COOKIE_DOMAIN, false);
wp_redirect( $location);
exit;
}
}
}
add_action( 'admin_init', 'set_noletia_gestor_portadas_cookie');
/***********************************************************************************************************/
//**** END COOKIES ******//
/***********************************************************************************************************/
function get_category_id($cat_name){
$term = get_term_by('slug', $cat_name, 'category');
return $term->term_id;
}
function get_category_slug_from_name($cat_name){
$term = get_term_by('name', $cat_name, 'category');
return $term->slug;
}
function get_category_id_from_slug($cat_slug){
$term = get_term_by('slug', $cat_slug, 'category');
return $term->term_id;
}
function get_category_name_from_slug($cat_slug){
$term = get_term_by('slug', $cat_slug, 'category');
return $term->name;
}
// Insertar Breadcrumb
function the_breadcrumb() {
$prov = $_COOKIE['noletia_prov'];
if (!is_front_page()) {
echo '<h2 id="breadcrumb-title"><a class="black size26" href="';
echo get_option('home');
echo '">Inicio</a>';
if(is_category() || is_tag()){
echo '<span class="breadcrumb-title2 size26"> | '.wp_title( false, false ).'</span>';
}else
if (is_page()) {
echo '<span class="breadcrumb-title2 size26"> | '.get_the_title().'</span>';
}
echo '</h2>';
}else{
echo '<h2 id="breadcrumb-title"><a class="black size26" href="'.get_bloginfo('home').'">Inicio</a>';
if($prov != 'todas'){
echo '<span class="breadcrumb-title2 size26"> | '.$prov.'</span>';
}
echo '</h2>';
}
}
// fin breadcrumb
// Insertar Breadcrumb
function noletia_the_path() {
global $post;
$prov = $_COOKIE['noletia_prov'];
$the_post_type = get_post_type($post->ID);
if(is_front_page()){
echo '<h2 id="breadcrumb-title">Inicio';
if($prov != 'todas'){
echo '<span class="breadcrumb-title2 size26"> | '.$prov.'</span>';
}
echo '</h2>';
}else{
echo '<h2 id="breadcrumb-title">';
if(is_category() || is_tag()){
if(in_category('el-club-express-tv')){
echo 'El Club Express Tv';
}else{
echo wp_title( false, false );
}
}elseif(is_search()){
printf( __( '%1$s', 'buddypress' ), wp_title( false, false ) );
}else{
if(is_single()){
if(in_category('musica')){
echo 'Música';
}elseif(in_category('artes-escenicas')){
echo 'Artes escénicas';
}elseif(in_category('arte')){
echo 'Arte';
}elseif(in_category('literatura')){
echo 'Literatura';
}elseif(in_category('audiovisual')){
echo 'Audiovisual';
}elseif(in_category('formacion')){
echo 'Formación';
}elseif(in_category('descuentos')){
echo 'Descuentos';
}elseif(in_category('concursos')){
echo 'Concursos';
}elseif(in_category('el-club-express-tv')){
echo 'El Club Express Tv';
}else{
if($the_post_type == 'event' || $the_post_type == 'event-recurring'){
if(is_object_in_term($post->ID, 'event-categories','descuentos')){
echo 'Descuentos';
}elseif(is_object_in_term($post->ID, 'event-categories','concursos')){
echo 'Concursos';
}else{
echo 'Agenda';
}
}else{
echo 'Actualidad';
}
}
}else{
if(is_page('agenda')){
echo 'Próximos eventos';
}else{
$the_title = get_the_title();
if($the_title != 'Música' && $the_title != 'Artes escénicas' && $the_title != 'Arte' && $the_title != 'Literatura' && $the_title != 'Audiovisual' && $the_title != 'Formación' && $the_title != 'Agenda' && $the_title != 'Descuentos' && $the_title != 'Concursos' && $the_title != 'Descargas' && $the_title != 'Newsletter'){
echo 'Noticias';
}else{
echo get_the_title();
}
}
}
}
//Los singles de eventos mostrarán la provincia a la que pertenezca el evento, no la provincia de la cookie:
if(($the_post_type == 'event' || $the_post_type == 'event-recurring') && !is_search()){
$prov = '';
if(is_object_in_term( $post->ID, 'event-categories', 'a-coruna')){
$prov .= ' | A Coruña';
}if(is_object_in_term($post->ID, 'event-categories', 'almeria')){
$prov .= ' | Almería';
}if(is_object_in_term($post->ID, 'event-categories', 'cadiz')){
$prov .= ' | Cádiz';
}if(is_object_in_term($post->ID, 'event-categories', 'ciudad-real')){
$prov .= ' | Ciudad Real';
}if(is_object_in_term($post->ID, 'event-categories', 'cordoba')){
$prov .= ' | Córdoba';
}if(is_object_in_term($post->ID, 'event-categories', 'granada')){
$prov .= ' | Granada';
}if(is_object_in_term($post->ID, 'event-categories', 'huelva')){
$prov .= ' | Huelva';
}if(is_object_in_term($post->ID, 'event-categories', 'malaga')){
$prov .= ' | Málaga';
}if(is_object_in_term($post->ID, 'event-categories', 'madrid')){
$prov .= ' | Madrid';
}if(is_object_in_term($post->ID, 'event-categories', 'ourense')){
$prov .= ' | Ourense';
}if(is_object_in_term($post->ID, 'event-categories', 'sevilla')){
$prov .= ' | Sevilla';
}if(is_object_in_term($post->ID, 'event-categories', 'toledo')){
$prov .= ' | Toledo';
}
echo '<span class="breadcrumb-title2 size26">'.$prov.'</span>';
}else{
if($prov != 'todas' && !is_search() && !is_page('facebook')){
echo '<span class="breadcrumb-title2 size26"> | '.$prov.'</span>';
}
}
echo '</h2>';
}
}
// fin breadcrumb
//Función para personalizar los cuadros de búsqueda por defecto
function noletia_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Buscar') .'" />
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'noletia_search_form' );
//Función para mostrar el formulario de login en la cabecera
function noletia_login_header(){
if ( is_user_logged_in() ) : ?>
<?php do_action( 'bp_before_sidebar_me' ) ?>
<div id="sidebar-me">
<?php /* ?><a href="<?php echo bp_loggedin_user_domain() ?>">
<?php bp_loggedin_user_avatar( 'type=thumb&width=30&height=30' ) ?>
</a><?php */ ?>
<h4>¡Hola <?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?>!</h4>
</div>
<div id="access-button">
<?php $back_url = get_permalink(); ?>
<a class="button logout" href="<?php echo wp_logout_url( $back_url ) ?>"><?php _e( 'Cerrar sesión', 'buddypress' ) ?></a>
</div>
<?php do_action( 'bp_sidebar_me' ) ?>
<?php do_action( 'bp_after_sidebar_me' ) ?>
<?php if ( bp_is_active( 'messages' ) ) : ?>
<?php bp_message_get_notices(); /* Site wide notices to all users */ ?>
<?php endif; ?>
<?php else : ?>
<?php do_action( 'bp_before_sidebar_login_form' ) ?>
<p>Indentifícate o <a target="_blank" href="<?php bloginfo('home'); ?>/registro/">regístrate</a> | <a href="<?php bloginfo('home'); ?>/porque-registrarse/">¿Por qué registrarse?</a></p>
<form name="login-form" id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login_post' ) ?>" method="post">
<input type="text" name="log" id="sidebar-user-login" class="input" value="<?php if ( isset( $user_login) ) echo esc_attr(stripslashes($user_login)); ?>" tabindex="97" />
<input type="password" name="pwd" id="sidebar-user-pass" class="input" value="" tabindex="98" />
<input type="submit" name="wp-submit" id="sidebar-wp-submit" value="<?php _e( 'Entrar', 'buddypress' ); ?>" tabindex="100" />
<p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="sidebar-rememberme" value="forever" tabindex="99" /> <?php _e( 'Recuérdame', 'buddypress' ) ?></label></p>
<?php echo '<p class="forgot_pass"><a href="'.get_bloginfo('home').'/wp-login.php?action=lostpassword">¿Olvidó su contraseña?</a></p>'; ?>
<?php do_action( 'bp_sidebar_login_form' ) ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI'];?>" />
<input type="hidden" name="testcookie" value="1" />
</form>
<?php do_action( 'bp_after_sidebar_login_form' ) ?>
<?php endif;
}
//Función para comprobar si nos encontramos en alguna de las portadas de sección: Música, Arte, etc.
function nombre_portada_de_seccion(){
$es_portada_de_seccion = '';
if(is_page('musica')){
$es_portada_de_seccion = 'musica';
}elseif(is_page('artes-escenicas')){
$es_portada_de_seccion = 'artes-escenicas';
}elseif(is_page('arte')){
$es_portada_de_seccion = 'arte';
}elseif(is_page('literatura')){
$es_portada_de_seccion = 'literatura';
}elseif(is_page('audiovisual')){
$es_portada_de_seccion = 'audiovisual';
}elseif(is_page('formacion')){
$es_portada_de_seccion = 'formacion';
}
return $es_portada_de_seccion;
}
/***********************************************************************************************************/
//**** FUNCIÓN PARA MOSTRAR EL SLIDE DE LAS PORTADAS ******//
/***********************************************************************************************************/
function noletia_show_main_slide($tipo_portada){
global $wpdb;
$prov_slug = get_category_slug_from_name($_COOKIE['noletia_prov']);
if($_COOKIE['noletia_prov'] != ''){
$prov_selected = ' cat_ID="'.get_category_id($_COOKIE['noletia_prov']).'"';
}else{
$prov_selected = '';
}
if($prov_selected == ''){
$opciones_prefijo = 'noletia_'.$tipo_portada.'_todas_';
}else{
$opciones_prefijo = 'noletia_'.$tipo_portada.'_'.$prov_slug.'_';
}
$slide1 = get_option( $opciones_prefijo.'slide1' );
if($slide1 != 0){
$slide2 = get_option( $opciones_prefijo.'slide2' );
$slide3 = get_option( $opciones_prefijo.'slide3' );
$slide4 = get_option( $opciones_prefijo.'slide4' );
$slides = $slide1.','.$slide2.','.$slide3.','.$slide4;
if(is_plugin_active('spd-shortcode-slider/spd-shortcode-slider.php')){
$spd_string = '[spd_slider max_slides="4" slider_display_slide_excerpt="no" slider_layout="numbers-bottom" post_type="post" pageorpost_ids="'.$slides.'" slide_img_size="new-slide-img"]';
}
}else{
$provincia_portada = $_COOKIE['noletia_prov'];
if($tipo_portada == 'global' && $provincia_portada == 'todas'){
$entradas = new WP_Query( 'post_status=publish&order=DESC&orderby=rand&posts_per_page=4&post_type=post&category__not_in=47' );
}else{
$cat_in = '';
$flag = '';
$flag2 = '';
if($tipo_portada != 'global'){ $cat_in .= $tipo_portada; $flag = 'y'; }
if($provincia_portada != 'todas'){ if($flag == 'y'){ $cat_in .= ','; $flag2 = 'y'; } $cat_in .= $provincia_portada; }
//Si se filtra por provinca y por tipo, tenemos que utilizar category__and
if($flag2 != 'y'){
$entradas = new WP_Query( 'post_status=publish&order=DESC&orderby=rand&posts_per_page=4&post_type=post&category__not_in=47&category_name='.$cat_in );
}else{
$cat1 = get_category_id($tipo_portada);
$cat2 = get_category_id($provincia_portada);
$cat1_and_cat2 = array($cat1,$cat2);
$query = array('post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'rand', 'posts_per_page' => 4, 'post_type' => 'post', 'category__not_in' => 47, 'category__and' => $cat1_and_cat2);
$entradas = new WP_Query($query);
}
}
// The Loop para el SLIDE
$slides = '';
$cont_articulos = 0;
while ( $entradas->have_posts() ) : $entradas->the_post();
if($cont_articulos > 0){ $slides .= ','; }
$slides .= get_the_id();
$cont_articulos++;
endwhile;
// Reset Post Data
wp_reset_postdata();
//Si no hay noticias con esas características, mostramos el general
if($slides == ''){
if(is_plugin_active('spd-shortcode-slider/spd-shortcode-slider.php')){
$spd_string = '[spd_slider max_slides="4" slider_display_slide_excerpt="no" slider_layout="numbers-bottom" post_type="post" slide_img_size="new-slide-img"]';
}
}else{
if(is_plugin_active('spd-shortcode-slider/spd-shortcode-slider.php')){
$spd_string = '[spd_slider max_slides="4" slider_display_slide_excerpt="no" slider_layout="numbers-bottom" post_type="post" pageorpost_ids="'.$slides.'" slide_img_size="new-slide-img"]';
}
}
}
do_shortcode($spd_string);
}
/***********************************************************************************************************/
//**** FUNCIÓN PARA MOSTRAR EL SLIDE DE LAS PORTADAS DE DESCUENTOS ******//
/***********************************************************************************************************/
function noletia_show_main_slide_descuentos($tipo_portada){
global $wpdb;
$current_date = microtime();
$current_date_secs = explode(" ",$current_date);
$current_date = $current_date_secs[1];
$prov_slug = get_category_slug_from_name($_COOKIE['noletia_prov']);
if($_COOKIE['noletia_prov'] != '' && $_COOKIE['noletia_prov'] != 'todas'){
$prov_selected = ' tax_slug="event-categories" term_slug="'.$tipo_portada.','.$prov_slug.'"';
$opciones_prefijo = 'noletia_'.$tipo_portada.'_'.$prov_slug.'_';
}else{
$prov_selected = ' tax_slug="event-categories" term_slug="'.$tipo_portada.'"';
$opciones_prefijo = 'noletia_'.$tipo_portada.'_todas_';
}
$slide1 = get_option( $opciones_prefijo.'slide1' );
if($slide1 != 0){
$slide2 = get_option( $opciones_prefijo.'slide2' );
$slide3 = get_option( $opciones_prefijo.'slide3' );
$slide4 = get_option( $opciones_prefijo.'slide4' );
$slides = $slide1.','.$slide2.','.$slide3.','.$slide4;
if(is_plugin_active('spd-shortcode-slider/spd-shortcode-slider.php')){
$spd_string = '[spd_slider max_slides="4" slider_display_slide_excerpt="no" slider_layout="numbers-bottom" post_type="event" pageorpost_ids="'.$slides.'" slide_img_size="new-slide-img"]';
}
}else{
$prov = $_COOKIE['noletia_prov'];
//Mostramos los descuentos de la provincia seleccionada
if($prov != '' && $prov != 'todas'){
$cont_eventos = 0;
$args = array( 'post_status' => 'publish', 'posts_per_page' => 4, 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => '_event_start_date', 'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
),
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( $prov_portada )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
$silde_descuentos_ids = new WP_Query($args);
if ($silde_descuentos_ids->have_posts()){
while ( $silde_descuentos_ids->have_posts() ){ $silde_descuentos_ids->the_post();
if($cont_eventos > 0){ $slides .= ','; }
$slides .= get_the_ID();
$cont_eventos++;
}
}
}
//Si no hay ningún descuento para esa provincia, que muestre los de la general
if($cont_eventos == 0 || $prov == '' || $prov == 'todas'){
$cont_eventos = 0;
$args = array( 'post_status' => 'publish', 'posts_per_page' => 4, 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => '_event_start_date', 'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
$modulo_concursos_ids = new WP_Query($args);
if ($modulo_concursos_ids->have_posts()){
while ( $modulo_concursos_ids->have_posts() ){ $modulo_concursos_ids->the_post();
if($cont_eventos > 0){ $slides .= ','; }
$slides .= get_the_ID();
$cont_eventos++;
}
}
}
if(is_plugin_active('spd-shortcode-slider/spd-shortcode-slider.php')){
$spd_string = '[spd_slider max_slides="4" slider_display_slide_excerpt="no" slider_layout="numbers-bottom" post_type="event" pageorpost_ids="'.$slides.'" slide_img_size="new-slide-img"]';
}
}//End de la opción automática
do_shortcode($spd_string);
}
/***********************************************************************************************************/
//**** FUNCIÓN PARA MOSTRAR LOS CONCURSOS DE LAS PORTADAS ******//
/***********************************************************************************************************/
//Función para mostrar los últimos eventos de la categoría Concursos en la portada
function mostrar_ult_post_concursos($tipo_portada){
global $wpdb;
$prov_portada = (isset($_COOKIE['noletia_prov'])) ? $_COOKIE['noletia_prov'] : 'todas';
$tipo_portada = (($tipo_portada == '')) ? 'global' : $tipo_portada;
$concurso1 = get_option( 'noletia_'.$tipo_portada.'_'.$prov_portada.'_concurso1' );
$concurso2 = get_option( 'noletia_'.$tipo_portada.'_'.$prov_portada.'_concurso2' );
$concurso3 = get_option( 'noletia_'.$tipo_portada.'_'.$prov_portada.'_concurso3' );
$concurso4 = get_option( 'noletia_'.$tipo_portada.'_'.$prov_portada.'_concurso4' );
$current_date = microtime();
$current_date_secs = explode(" ",$current_date);
$current_date = $current_date_secs[1];
//Si han seleccionado, al menos un concurso de forma manual, se mostrarán los seleccionados
if($concurso1 != '' && $concurso1 != 0){
$concursos_in = array($concurso1,$concurso2,$concurso3,$concurso4);
$args = array( 'post_type' => 'event', 'post__in' => $concursos_in);
//Si en la gestión de portadas no se ha seleccionado el concurso1, entonces se mostrarán de forma automática
}else{
if($tipo_portada == 'global' && $prov_portada == 'todas'){
$args = array( 'posts_per_page' => 4, 'post_type' => 'event', 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
}elseif($tipo_portada == 'global' && $prov_portada != 'todas'){
$prov_id = get_cat_ID($prov_portada);
$args = array( 'posts_per_page' => 4, 'post_type' => 'event', 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
),
array(
'taxonomy' => 'event-categories',
'field' => 'id',
'terms' => array( $prov_id )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
}elseif($tipo_portada != 'global' && $prov_portada == 'todas'){
$args = array( 'posts_per_page' => 4, 'post_type' => 'event', 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
),
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( $tipo_portada )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
}elseif($tipo_portada != 'global' && $prov_portada != 'todas'){
$prov_id = get_cat_ID($prov_portada);
$args = array( 'posts_per_page' => 4, 'post_type' => 'event', 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
),
array(
'taxonomy' => 'event-categories',
'field' => 'id',
'terms' => array( $prov_id )
),
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( $tipo_portada )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
}
}
$the_query = new WP_Query( $args );
$cont = 0;
if ($the_query->have_posts()) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$concurso_id = get_the_ID();
if(has_post_thumbnail() && $cont == 0):
echo '<div class="imagen-descuentos"><a href="'.get_permalink().'">';
echo get_the_post_thumbnail($concurso_id, 'thumbnail');
echo '</a><a href="'.get_bloginfo('home').'/concursos/"><span class="info"><h3>concursos</h3></span>';
echo '</a></div>';
endif;
//if($cont == 0){ echo '<ul>'; }
$event_start_date = $wpdb->get_var("SELECT event_start_date FROM wp_em_events WHERE post_id = '$concurso_id'");
$date_event = date_i18n('d/m/Y', strtotime($event_start_date));
/*echo '<li';
if($cont == 0) { echo ' class="last-li-event"'; }
echo '><a href="' . get_permalink() . '">'.get_the_title().' <span class="event-portada-date">'.$date_event.'</span></a></li>';*/
if($cont == 0){ echo '<div id="list_concur_frontpage"><ul>'; }
echo '<li';
if($cont == 0) { echo ' class="last-li-concur"'; }
echo '><a href="' . get_permalink() . '"><p class="list_concurs_frontpage_title">'.get_the_title().' </p><p class="concur-portada-date">'.$date_event.'</p></a></li>';
$cont++;
endwhile;
if($cont != 0): echo '</ul></div>'; endif;
else:
//Si en cualquiera de los casos anteriores, la query sale vacía, que muestre todos los últimos Concursos (global-todas)
$args = array( 'posts_per_page' => 4, 'post_type' => 'event', 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => array( 'concursos' )
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_start_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
),
array(
'key' => '_end_ts',
'value' => $current_date,
'type' => 'NUMERIC',
'compare' => '>='
)
)
);
$the_query2 = new WP_Query( $args );
$cont = 0;
if ($the_query2->have_posts()){
while ( $the_query2->have_posts() ) : $the_query2->the_post();
$concurso_id = get_the_ID();
if(has_post_thumbnail() && $cont == 0):
echo '<div class="imagen-descuentos"><a href="'.get_permalink().'">';
echo get_the_post_thumbnail($concurso_id, 'thumbnail');
echo '</a><a href="'.get_bloginfo('home').'/concursos/"><span class="info"><h3>concursos</h3></span>';
echo '</a></div>';
endif;
//if($cont == 0){ echo '<ul>'; }
$event_start_date = $wpdb->get_var("SELECT event_start_date FROM wp_em_events WHERE post_id = '$concurso_id'");
$date_event = date_i18n('d/m/Y', strtotime($event_start_date));
/*echo '<li';
if($cont == 0) { echo ' class="last-li-event"'; }
echo '><a href="' . get_permalink() . '">'.get_the_title().' <span class="event-portada-date">'.$date_event.'</span></a></li>';*/
if($cont == 0){ echo '<div id="list_concur_frontpage"><ul>'; }
echo '<li';
if($cont == 0) { echo ' class="last-li-concur"'; }
echo '><a href="' . get_permalink() . '"><p class="list_concurs_frontpage_title">'.get_the_title().' </p><p class="concur-portada-date">'.$date_event.'</p></a></li>';
$cont++;
endwhile;
if($cont != 0) echo '</ul></div>';
}else{
?>
<div class="imagen-descuentos"><img src="http://elclubexpress.com/wp-content/uploads/low1-658x320-345x200.jpg" class="attachment-thumbnail wp-post-image" alt="low1-658x320" title="low1-658x320" height="200" width="345"><span class="info"><h3>concursos</h3></span>
</div>
<div id="list_concur_frontpage"><ul><li class="last-li-concur"><p class="list_concurs_frontpage_title">PRÓXIMAMENTE</p><p class="concur-portada-date"></p></li></ul>
</div>
<?php
}