最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Feature image Gallery made from Custom Post type + Categories

programmeradmin3浏览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.

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

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.

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

Share Improve this question edited Apr 17, 2020 at 10:59 Azury asked Apr 17, 2020 at 10:50 AzuryAzury 12 bronze badges 4
  • You may do it either by ajax or traditional (page loading) way, which one you prefer? – 西門 正 Code Guy - JingCodeGuy 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? – 西門 正 Code Guy - JingCodeGuy 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
Add a comment  | 

1 Answer 1

Reset to default 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();
?>
发布评论

评论列表(0)

  1. 暂无评论