Get posts by category via ajax
In my page-members.php
I output my list of categories
?php
$args = array(
'orderby' = 'slug'
);
$categories = get_categories($args);
foreach ($categories as $category) {
echo 'a href="' . get_category_link($category-term_id) . '"div class="category-block"' . $category-name . '/div/a';
}
?
I'd like for a click on those links to fill the right column with the posts of that category.
I have a js file loaded for this page; my functions.php
:
if (is_page()) {
global $post;
if ($post-post_name == 'members') {
wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery.js', array(), '', true);
wp_enqueue_script('blog', get_template_directory_uri() . '/js/blog.js', array('jquery'), '', true);
wp_localize_script('blog', 'ajaxposts', array(
'ajaxurl' = admin_url('admin-ajax.php')
));
}
}
My blog.js
loads appropriately only on the members page.