Jump to content
quickjeff

Images Advice

Recommended Posts

Hi Guys, 
 
So I am working on a project and wanted to get the best advice using the api on the next step. 

I have two image fields in one template. 

postimage which holds an image for the article and postimage2 which holds an image for the home page.

Basically I want to make it so that when a user uploads postimage and not postimage2 the home page will just pickup postimage instead. 

If the user does upload postimage2, it should pick up postimage2. 

What I did:

I did add a conditional statement to check if postimage2 was empty to simply default to postimage but I was not seeing any images display. 

Here is my code:

<?php  

foreach($featured as $featuredp){

   
 foreach($featuredp->postimage2 as $postimages2) {

        echo"<div class=\"row panel\" style=\"margin:20px auto;\">";
 
echo"<div class=\"large-4 columns\"><p> <a href='{$featuredp->url}'><img src='{$postimages2->url}' width=\"300\"/></a></p></div>"; 

echo"<div class=\"large-8 columns\">

<h4>{$featuredp->title}</h4>
<p><em>{$featuredp->date}</em></p>
<p>{$featuredp->summary}</p>
<p><a href=\"{$featuredp->url}\" class=\"button tiny radius\">Read More</a></p>

        </div>
</div>";


            $found = 1;
            
            
            }

            }
            
         
            if ( ! $found )
            
            {
            
            echo"<p>Sorry, no posts.</p>";
            
            
            }

?>

Any advice is appreciated?  Also any suggestions or workarounds are also welcome!

Share this post


Link to post
Share on other sites

I solved my own issue, I ended up using one image field and using the limit=1 method. Works like a charm!

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By humanafterall
      I'm using some Custom fields for images: 
      https://processwire.com/blog/posts/pw-3.0.142/#custom-fields-for-files-images

      When I save the page, and return the fields are blank. When I re-add the text to the fields and save again then the fields save as expected.

      I know this is stated as being quite experimental but it's super useful feature I'd love to get working correctly.
      I have fields that are CKEditor fields but have overidden this on the image specific template. I've also tried it with regular text fields and I get the same bug.
      (currently using Processwire 3.0.155)
      **UPDATE**
      I've found this issue is specific to editing on pages using the PageTable fieldtype. The fields are not saving when I save the page in the PageTable.
    • By Robin S
      Displays image tags overlaid on the thumbnail using customisable colours. This makes it easier to see which images have which tags without needing to open the edit pane for individual images or changing to the list view.
      Screenshot

      Usage
      Enable tags for one or more image fields. Install the Image Thumbnail Tags module. Optionally configure colours for any of your tags.
       
      https://github.com/Toutouwai/ImageThumbnailTags
      https://modules.processwire.com/modules/image-thumbnail-tags/
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
      Thanks! 
×
×
  • Create New...