0

Hey guys im trying to find a way to create a little gallery (Will post a image of what I need) Using Custom post type's Featured Image's where I can swap the image's based on category

I have 0 idea how to go about this and really need some advice.

enter image description here

I can probably create the layout my self, Im just trying to keep this as simple as possible for the next person to understand, So I would just be swapping out the Images for other one's depending on the Category selected

I have the custom post type already it's called

Brands/Brand/brand

Also I do have toolset if that helps atall

4
  • You may do it either by ajax or traditional (page loading) way, which one you prefer? Commented Apr 17, 2020 at 10:54
  • I guess ajax is less evasive because it doesnt require a full reload correct? so ajax id say
    – Azury
    Commented Apr 17, 2020 at 10:58
  • So you are going to build a template, right? I think first thing you need to know is understand how's the loop operation in WordPress. Then you need to know how to fetch the post data in the loop according to Category. And then you need to learn a bit how to code the ajax way in WordPress. Do you familiar with php, js and html? Are you prepared to get your hand dirty with coding? Commented Apr 17, 2020 at 11:01
  • ofcourse yes Cant say im to familiar with ajax but i do know some php and comfy with js html ofcourse
    – Azury
    Commented Apr 17, 2020 at 11:04

1 Answer 1

0

Given that there is a custom post type in the code. And what you may want to do includes a few steps and tests. The following may help in kicking start and continue to explore. The best things to do is always testing in a fundamental environment without plugins and theme interference by using the default theme and turn off unnecessary plugins. This could also save a lot of time.

  • Use a query to create a loop and get the custom posts (put in argument to query with custom post type and custom taxonomy...etc)
  • fetch the image from the post during the loop using such as get_the_post_thumbnail()
  • after fetching and output the gallery image and style it with css, may add custom style/script in theme functions.php with hook wp_enqueue_scripts and function wp_enqueue_script()
  • for the above is satifised, may also consider pagination
  • After successfully doing a traditional page loading version with pagination. The concept for using ajax is similar, could refer to Handbook about Ajax, but just need to use WP way to accomplish it. May also refer to practical example in this post too.

The following could be put in any template other than homepage. For page being set to frontpage, the behaviour of the loop variable is a little bit different.

<?php
// a simple query to a custom post could help to start
// create a query in the template

// could explore more about the arguments through the above links
$args = array(
    'post_type'         => 'brand',
);

$query = new WP_Query($args);

while ($query->have_posts()) {
    $query->the_post();

    // output the image here
}
wp_reset_postdata();
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.