Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6120869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:43:03+00:00 2026-05-23T15:43:03+00:00

The site I am working on uses many content types and almost all of

  • 0

The site I am working on uses many content types and almost all of them use one or more image fields.
Image fields are not shared between content types, so there is a big number of them.

What I need is to get the first image field from a node, assuming there are more image fields linked to a node and without knowing the name of any of these fields. The first one is considered to be the one with a lower weight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:43:04+00:00Added an answer on May 23, 2026 at 3:43 pm

    This should build you an array of the “lightest” imagefield per content type.

    <?php
    module_load_include('inc', 'content', 'includes/content.node_form');
    $content_types = array('page', 'story', 'product', 'some_content_type');
    
    $lightest_imagefields = array(); // arranged by content type
    foreach ($content_types as $content_type_name) {
      $content_type_data = content_types($content_type_name);
      $last_weight = NULL;
      foreach ($content_type_data['fields'] as $field_name => $field_data) {
        if ($field_data['widget']['type'] == 'imagefield_widget' && (is_null($last_weight) || (int)$field_data['widget']['weight'] < $last_weight)) {
            $lightest_imagefields[$content_type_name] = $field_name;
            $last_weight = (int)$field_data['widget']['weight'];
        }
      }
    }
    /** Hypothetical Usage:
     * $node = load_some_node_i_want();
     * $node->$lightest_imagefields[$node->type]; // Access this node's lightest imagefield.
     */
    

    Then when you load a node of, say, the “product” content type, you know which imagefield is the lightest (i.e $node->$lightest_imagefields[$node->type]).

    Hope it helps. (test it before using it, though!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site which uses overlay pages, all was working fine until I
I'm currently working on a site that uses ajax to load the content into
A site I'm working on takes table data, counts that table data and uses
I'm working on a site which uses the Facebook API to log users in,
I am working on a URL shortening site which uses PHP, MySQL and Apache.
I am working on a site that uses Facebook Connect for user login/creation. I
I am working on a public facing MOSS 2007 site that uses the ViewFormPagesLockDown
I'm working on a new layout for my site that uses a header, footer
I am working on a site maintainence. It uses mod_rewrite technique. But im new
I'm working on a site (MVC) at the moment, which uses ajax quite heavily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.