Example #1
0
function register_route($data, $post_type)
{
    // add the query params from API request to an array
    $params = $data->get_query_params();
    // build the query args array
    $args['post_type'] = $post_type;
    // loop through the params and add to query args
    foreach ($params as $param => $value) {
        $args[$param] = $value;
    }
    $posts = get_posts($args);
    // get the template we need to load
    if (is_array($post_type)) {
        $template = implode('_', $post_type);
    } else {
        $template = $post_type;
    }
    // loop through posts and load the html
    $i = 0;
    $homeID = '';
    foreach ($posts as $post => $value) {
        $id = $value->ID;
        if ($id == get_option('page_on_front')) {
            $template = 'home';
        }
        $results[$i] = new stdClass();
        $results[$i]->ID = $id;
        $results[$i]->html = load_template_part($id, $template);
        $results[$i]->pageTitle = get_the_title($id) . ' - ' . get_bloginfo();
        $i++;
    }
    return $results;
}
function social_func($atts)
{
    extract(shortcode_atts(array('foo' => 'something', 'bar' => 'something else'), $atts));
    $icons = load_template_part('social', 'profiles');
    return $icons;
}
Example #3
0
function get_posts_content($pages)
{
    $results;
    global $page;
    foreach ($pages as $page) {
        $slug = $page->post_name;
        $template = get_page_template_slug($page->ID);
        $template = str_replace('.php', '', $template);
        $content = load_template_part($template);
        $results[$slug] = $content;
    }
    return $results;
}
Example #4
0
function getMorePostsAJAX()
{
    global $wp_query;
    $paged = max(1, $_POST['pagenumber']);
    $cat = isset($_POST['cat']) ? $_POST['cat'] : '';
    $args = array('paged' => $paged, 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'category_name' => $cat);
    srand(make_seed());
    $randval = rand();
    $GLOBALS['loop_rand'] = $randval;
    query_posts($args);
    if ($paged > $wp_query->max_num_pages) {
        die;
    }
    $arr['html'] = load_template_part('loop');
    $arr['loop'] = getLoopRand();
    $arr['args'] = $args;
    echo json_encode($arr);
    die;
}
 /**
  * Insert the newsletter signup in posts automatically
  */
 public function insert_bna_signup_in_content($content)
 {
     if (!is_single()) {
         return $content;
     }
     $post = get_post();
     $cat = get_the_category();
     $catnames = array();
     $is_queue = false;
     if (is_array($cat)) {
         foreach ($cat as $category) {
             $catnames[] = $category->cat_name;
         }
         if (in_array('The Queue', $catnames)) {
             $is_queue = true;
         }
     }
     if (str_word_count($post->post_content) < 200 && $is_queue != true) {
         return $content;
     }
     if (get_field('hide_nl_signup')) {
         return $content;
     }
     $last_offset = strrpos($content, "<p>");
     $computed_offset = -1 * (strlen($content) - $last_offset) - 4;
     $next_to_last_offset = strrpos($content, "<p>", $computed_offset);
     $newsletter_signup = load_template_part('templates/in-article', 'newsletter-signup');
     $content = substr_replace($content, $newsletter_signup, $next_to_last_offset, 0);
     return $content;
 }
Example #6
0
/**
 * Custom wrapper to load the partials files enabling the pass of parameters
 * to the partial as local variables.
 *
 * @since 2.0.0
 *
 * @param string $file_name The name of the file to load.
 * @param array  $args Extra variables to pass to the partial.
 */
function load_partial($file_name = '', $args = [])
{
    $path = '/partials/' . $file_name;
    load_template_part($path, $args);
}