• I am building a custom wordpress theme from scratch. So far it is going great, but I have a problem with a image-based portfolio page I have in mind.

    What I want to achieve is to make a portfolio page (using a grid) that automatically updates when I add new photos… Either on top or at the bottom of my grid.

    I think the way to go is to create a loop that keeps creating grid items as long as there are images.

    My questions:
    – Is it even possible to upload pictures, either on the specific page with the builder or in the dashboard, and pick specific images with that loop for my portfolio page? Because in the dashboard are all the images for the website uploaded, but only some are for my portfolio page. How can I select the right images for my loop?

    – How do I create that loop? I have succesfully created loops that upload all the images, but now I want a loop only picking some. Also, a loop with post attachments also didnt work somehow.

    Thanks for the help! Any other ideas to create automatically-updating portfolio pages are welcome.

    • This topic was modified 2 years, 3 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • For your idea I see several possibilities of implementation. Which one you choose depends on how you want to make it accessible to the users of your theme.

    Possibility 1:
    Folder images that should be displayed in the portfolio to a category. To do this, you must first activate the categories for media files. This can be done e.g. with this snippet:

    function add_categories_for_attachments() {
        register_taxonomy_for_object_type( 'category', 'attachment' );
    }
    add_action( 'init' , 'add_categories_for_attachments' );

    Then you create a category when you install your theme, e.g. “Portfolio”, and let the editor assign all images that should be displayed there to the category.
    Where you then want to output the portfolio, you must query all images that are assigned to this category. This can be done e.g. with a WP_Query query.
    The disadvantage of this option is that there can only be 1 portfolio. And you would have to make it clear to the editor that he deposits labels that should be displayed on the image. This is certainly not very obvious, but for you it would be faster to implement in development than other options.

    Possibility 2:
    Create a Custom Post Type where you assign 1 image per record and if necessary add further texts. Take a look at this: https://developer.www.ads-software.com/plugins/post-types/registering-custom-post-types/ – you can also do this with themes.
    Also here you have to make a query where you want to output it, also doable with WP_Query.
    Disadvantage here is certainly that you have to write much more code. But for an editor it is clearer.

    As I said: it’s your decision which way you go. Depends on what you want to achieve with your theme.

    Thread Starter arwinio

    (@arwinio)

    Hi Threadi,

    Many thanks for your response.

    I am not creating a theme for other users, I am just creating a theme for self-use. So, as long as I know how it works its good.. ??

    So for option 1: why only possible to create 1 portfolio? If I can assign different categories to pictures and on two different pages make a quary for each category, would that not work?

    Option 2: So basically, create for each photo a custom post with that photo attached and with the quarry output all the custom posts?

    Thanks!

    Arwin

    Yes, you could also work with multiple categories. I just thought it might be confusing for editors. But you remember that for sure ??

    And yes, with option 2 you could use one record per image. With an additional taxonomy assigned only to your Custom Post Type, you could create as many categories / collections of portfolios as you want here too.

    Thread Starter arwinio

    (@arwinio)

    Thank you very much for your tips and help!

    I am going to try it out this week!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Photo quary for my portfolio page’ is closed to new replies.