示例#1
0
 /**
  * add meta_description
  *
  * hook after post has loaded to add a unique meta-description
  *
  */
 public static function meta_description()
 {
     $post = new \TimberPost();
     // check for custom field
     $description = wptexturize($post->get_field('meta_description'));
     if (is_tax()) {
         if ($temp = term_description(get_queried_object(), get_query_var('taxonomy'))) {
             $description = $temp;
         }
     } elseif (is_post_type_archive()) {
         if ($temp = get_the_archive_description()) {
             $description = $temp;
         }
     }
     // else use preview
     if (empty($description)) {
         $description = str_replace('', "'", $post->get_preview(40, true, false, true));
     }
     // finally use the blog description
     if (empty($description)) {
         $description = get_bloginfo('description', 'raw');
     }
     $description = esc_attr(wp_strip_all_tags($description));
     // limit to SEO recommended length
     if (strlen($description) > 155) {
         $description = substr($description, 0, 155);
         $description = \TimberHelper::trim_words($description, str_word_count($description) - 1);
     }
     return $description;
 }
示例#2
0
 /**
  * add meta_description
  *
  * hook after post has loaded to add a unique meta-description
  *
  */
 public static function meta_description()
 {
     $post = new \TimberPost();
     // check for custom field
     $description = wptexturize($post->get_field('meta_description'));
     // else use preview
     if (empty($description)) {
         $description = str_replace('', "'", $post->get_preview(40, true, false, true));
     }
     // finally use the blog description
     if (empty($description)) {
         $description = get_bloginfo('description', 'display');
     }
     $description = esc_attr($description);
     // limit to SEO recommended length
     if (strlen($description) > 155) {
         $description = substr($description, 0, 155);
         $description = \TimberHelper::trim_words($description, str_word_count($description) - 1);
     }
     return $description;
 }
                $response['lletra'] = $lletra;
                $response['result'] = $api_response;
                $title = 'Diccionari multilingüe: paraules que comencen per ' . $lletra;
                $content_title = 'Diccionari multilingüe. Lletra «' . $lletra . '»';
                $canonical = '/diccionari-multilingue/lletra/' . $lletra . '/';
                $context_holder['cerca_result'] = Timber::fetch('ajax/multilingue-lletra.twig', array('response' => $response));
            } else {
                throw_error('500', 'Error connecting to API server');
                $context_holder['cerca_result'] = 'S\'ha produït un error en contactar amb el servidor. Proveu de nou.';
            }
        } else {
            throw_error('404', 'No Results For This Search');
            $context_holder['cerca_result'] = 'Esteu utilitzant la cerca per lletra. Heu cercat <strong>' . $context['lletra'] . '</strong>. La cerca només pot contenir una lletra';
        }
    }
}
$context_filterer = new SC_ContextFilterer($context_holder);
$context_overrides = array('title' => $title, 'description' => $description, 'canonical' => $canonical);
$context = $context_filterer->get_filtered_context($context_overrides, false);
$context['post'] = $post;
$context['paraula'] = $paraula;
$context['lletra'] = $lletra;
$context['content_title'] = $content_title;
$context['links'] = $post->get_field('link');
$context['credits'] = $post->get_field('credit');
$context['sidebar_top'] = Timber::get_widgets('sidebar_top_recursos');
$context['sidebar_elements'] = array('static/ajudeu.twig', 'static/dubte_forum.twig', 'baixades.twig', 'links.twig');
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom_recursos');
//Contact Form
$context['contact']['to_email'] = get_option('email_recursos');
Timber::render(array('diccionari-multilingue.twig'), $context);
    $projecte->lectures_recomanades = apply_filters('the_content', $projecte->lectures_recomanades);
    $context_filterer = new SC_ContextFilterer();
    $context = $context_filterer->get_filtered_context(array('title' => $content_title . '| Softcatalà'));
    $context['projecte'] = $projecte;
    $context['steps'] = $projecte->get_field('steps');
    $templates = array('plantilla-steps-single.twig');
    $args = array('meta_query' => array(get_meta_query_value('projectes', $projecte->ID, 'like', '')));
    $context['membres'] = get_users($args);
} else {
    $post = Timber::get_post();
    $profile = $post->get_field('perfil');
    $profile_label = get_field_object('perfil', $post->ID);
    $all_acf_data = get_field_objects($post->ID);
    $content_title = 'Col·laboreu amb nosaltres: ' . $profile_label['choices'][$profile];
    if (false === $profile || empty($profile)) {
        wp_redirect('/col·laboreu/', 302);
    }
    $project_args = array('tax_query' => array(array('taxonomy' => 'ajuda-projecte', 'field' => 'slug', 'terms' => $profile), array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN')));
    $projects = $sc_types['projectes']->get_sorted_projects($project_args);
    $context = Timber::get_context();
    $context['projectes'] = $projects;
    $context['steps'] = $post->get_field('steps');
}
$post = new TimberPost();
$context['post'] = $post;
$context['content_title'] = $content_title;
$context['links'] = $post->get_field('link');
$context['sidebar_top'] = Timber::get_widgets('sidebar_top');
$context['sidebar_elements'] = array('static/dubte_forum.twig', 'baixades.twig', 'links.twig');
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom');
Timber::render($templates, $context);
/**
 * Template Name: Subpàgina Programa
 *
 * @package wp-softcatala
 */
wp_enqueue_script('sc-js-pmf', get_template_directory_uri() . '/static/js/pmf.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('jquery-browser-plugin', get_template_directory_uri() . '/static/js/jquery.browser.min.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('sc-js-programes', get_template_directory_uri() . '/static/js/programes.js', array('sc-js-main', 'jquery-browser-plugin'), WP_SOFTCATALA_VERSION, true);
wp_localize_script('sc-js-programes', 'scajax', array('ajax_url' => admin_url('admin-ajax.php')));
$context = Timber::get_context();
$post_subpagina = new TimberPost();
$context['sidebar_top'] = Timber::get_widgets('sidebar_top');
$context['sidebar_elements'] = array('baixades.twig', 'links.twig');
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom');
$context['post_subpagina'] = $post_subpagina;
$post = new TimberPost($post_subpagina->programa);
$logo = $post->logotip_programa;
$custom_logo_filter = function ($img) use($logo) {
    return $logo;
};
add_filter('wpseo_twitter_image', $custom_logo_filter);
add_filter('wpseo_opengraph_image', $custom_logo_filter);
$context['post'] = $post;
$context['content_title'] = $post->title . ' - PMF';
$query = array('post_id' => $post_subpagina->programa, 'subpage_type' => 'programa');
$args = get_post_query_args('page', SearchQueryType::PagePrograma, $query);
query_posts($args);
$context['related_pages'] = Timber::get_posts($args);
$baixades = $post->get_field('baixada');
$context['baixades'] = generate_url_download($baixades, $post);
Timber::render(array('subpagina-type.twig'), $context);
 public static function get_posts($lists, $manualPosts = null, $limitOverride = null, $offset = 0, $caresAboutDupes = true, $excludePosts = null)
 {
     global $post;
     $context = Timber::get_context();
     if (!is_array($lists)) {
         $lists = array($lists);
     }
     // Add manual which are live
     $posts = array();
     if ($manualPosts) {
         if (!is_array($manualPosts)) {
             $manualPosts = $manualPosts->get_posts();
         }
         foreach ($manualPosts as $manualPost) {
             if (get_post_status($manualPost) === 'publish') {
                 // if (true) {
                 if (is_numeric($manualPost) || get_class($manualPost) === 'WP_Post') {
                     $timberPost = new TimberPost($manualPost);
                     if (!$timberPost) {
                         throw new Exception('Expected Timber to initialise a post');
                     }
                 } else {
                     $timberPost = $manualPost;
                 }
                 $posts[] = $timberPost;
                 if ($caresAboutDupes) {
                     self::$dupes[] = $timberPost->id;
                 }
             }
         }
     }
     $limitOverride = $limitOverride - count($posts);
     // If manual lists already has enough content do not fetch from query
     if ($limitOverride <= 0) {
         return $posts;
     }
     $post_not_in = $caresAboutDupes ? self::$dupes : array();
     if ($excludePosts) {
         foreach ($excludePosts as $excludePost) {
             if (is_numeric($excludePost)) {
                 $post_not_in[] = $excludePost;
             } elseif (get_class($excludePost) === 'WP_Post' || get_class($excludePost) === 'TimberPost') {
                 $post_not_in[] = $excludePost->ID;
             }
         }
     }
     $date = date('Ymd H:i:s');
     $postsFromQuery = [];
     foreach ($lists as $list) {
         if (!$list) {
             continue;
         }
         $list_id = is_numeric($list) ? $list : $list->ID;
         if (!method_exists($list, 'get_field')) {
             $list = new TimberPost($list->ID);
         }
         $categories = [];
         if ($list->get_field('categories_configuration') === 'current-category-and-children') {
             $categories[] = self::get_current_category_from_url();
         } else {
             $categories = get_field("categories", $list_id) ?: [];
         }
         $post_type = null;
         if ($list->get_field('post_type_configuration') === 'current') {
             if ($post && isset($post->post_type)) {
                 $post_type = $post->post_type;
             }
         }
         $query_args = array('cat' => implode(',', $categories), 'posts_per_page' => $limitOverride ? $limitOverride : get_field("limit", $list->ID), 'post__not_in' => $post_not_in, 'no_found_rows' => 1, 'offset' => $offset, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('relation' => 'AND', array('key' => 'override_end_time', 'compare' => 'NOT EXISTS', 'value' => '1'), array('key' => 'override_start_time', 'compare' => 'NOT EXISTS', 'value' => '1')), array('relation' => 'AND', array('relation' => 'OR', array('key' => 'override_end_time', 'compare' => '>=', 'value' => time()), array('key' => 'override_end_time', 'compare' => '==', 'value' => '')), array('relation' => 'OR', array('key' => 'override_start_time', 'compare' => '<=', 'value' => time()), array('key' => 'override_start_time', 'compare' => '==', 'value' => ''))))));
         if ($post_type) {
             $query_args['post_type'] = $post_type;
         }
         $the_query = new WP_Query($query_args);
         // Merge each lists resulting post IDs into
         // $post_not_in to avoid dupes.
         $post_not_in = array_merge($post_not_in, array_map(function ($p) {
             return $p->ID;
         }, $the_query->posts));
         $postsFromQuery = array_merge($postsFromQuery, $the_query->posts);
         // Reduce the limit by amout of posts received.
         $limitOverride -= count($the_query->posts);
         if ($limitOverride <= 0) {
             break;
         }
     }
     foreach ($postsFromQuery as $post) {
         if (get_class($post) === 'WP_Post') {
             $timberPost = new TimberPost($post);
         } else {
             $timberPost = new $post();
         }
         $posts[] = $timberPost;
         if ($caresAboutDupes) {
             self::$dupes[] = $post->ID;
         }
         if (!$timberPost) {
             var_dump($timberPost);
             exit;
         }
     }
     return $posts;
 }