Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
I made a portfolio page and when im listing all portfolios i want to count how many image is saved to the spesiffic project.

Here is code so far:

<cms:pages masterpage='portfolio.php'>
<div class="block-box-1 block-box-2">
<ul>
<li class="block-box-first">
<div class="block-box-img">

<img class="" src="<cms:show slide />" alt=""/>

</div>
<div class="block-box-content">
<a href="#"><cms:show k_page_title /></a>
<span><i class="fa fa-user"></i>for : <cms:show port_client /></span>
<span><i class="fa fa-clock-o"></i><cms:date k_page_date format='F j, Y'/></span>

<span><i class="fa fa-image"></i><cms:show image_count /></span>

<div class="clearfix"></div>
<p><cms:excerptHTML count='120' ignore='img'><cms:show content /></cms:excerptHTML></p>
<a class="button post-more" href="<cms:show k_page_link />">Se flere bilder</a>
</div>
</li>
</ul>
<div class="clearfix"></div>
</div>

</cms:pages>
Maybe run 2 instances of pages tag?
1st to count images and 2nd is your posted code.
First part may look like:
Code: Select all
<cms:set image_count='0' />
<cms:pages masterpage='portfolio.php' custom_field="slide!==" >
   <cms:incr image_count />
</cms:pages>

Then you have image_count ready for publishing with the full code you provided. Did I understand your question at all?
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Almost, it now shows the number 0, but i want it to show the number of pictures related to the spessific post.

Some post have 1 image, some 2 and some up to 6 pictures.
@kimheggen,
want it to show the number of pictures related to the spessific post.
Some post have 1 image, some 2 and some up to 6 pictures.

Going by the code you posted -
Code: Select all
<cms:pages masterpage='portfolio.php'>
..
</cms:pages>
- I'll assume that each cloned page of template 'portfolio.php' has a variable number of images associated with it.

However, it is not clear from the post as to how you have defined those images? I can only see a single type 'image' region named 'slide'.

Normally when a variable number of images are to be associated with a post, we use a 'repeatable region' (or alternatively use nested gallery viewtopic.php?f=8&t=8559).

Could you please elaborate the setup you are using to add multiple images to a single post?
The code is:

<cms:template title='Portfolio' clonable='1'>
<cms:editable
name='content'
label='Beskrivelse'
desc='Enter description of portfolio item here'
type='richtext' />

<cms:editable name='port_client' label='Kunde navn' type='text' />

<cms:editable
name='website'
label='Website'
desc='Skriv web adresse her'
type='text'>
</cms:editable>

<cms:editable name='group_img1' label='Bilde 1' desc='Bilde 1' type='group' />
<cms:editable
name='image_1'
label='Bilde 1'
desc='Last opp bilde 1 her'
crop='1'
width='1140'
height='641'
group='group_img1'
type='image'
/>
<cms:editable
name='thumb'
label='Bilde thumb'
desc='Thumb av bilde 1'
width='70'
height='70'
show_preview='1'
assoc_field='image_1'
group='group_img1'
type='thumbnail'
/>
<cms:editable
name='slide'
label='Bilde slide'
desc='Slide av bilde 1'
width='600'
height='300'
show_preview='1'
assoc_field='image_1'
group='group_img1'
type='thumbnail'
/>

<cms:editable name='group_img2' label='Bilde 2' desc='Bilde 2' type='group' />
<cms:editable
name='image_2'
label='Bilde 2'
desc='Last opp bilde 2 her'
width='600'
height='300'
crop='1'
group='group_img2'
type='image'
/>

<cms:editable name='group_img3' label='Bilde 3' desc='Bilde 3' type='group' />
<cms:editable
name='image_3'
label='Bilde 3'
desc='Last opp bilde 3 her'
width='600'
height='300'
crop='1'
group='group_img3'
type='image'
/>
<cms:editable name='group_img4' label='Bilde 4' desc='Bilde 4' type='group' />
<cms:editable
name='image_4'
label='Bilde 4'
desc='Last opp bilde 4 her'
width='600'
height='300'
crop='1'
group='group_img4'
type='image'
/>
<cms:editable name='group_img5' label='Bilde 5' desc='Bilde 5' type='group' />
<cms:editable
name='image_5'
label='Bilde 5'
desc='Last opp bilde 6 her'
width='600'
height='300'
crop='1'
group='group_img5'
type='image'
/>
<cms:editable name='group_img6' label='Bilde 6' desc='Bilde 6' type='group' />
<cms:editable
name='image_6'
label='Bilde 6'
desc='Last opp bilde 6 her'
width='600'
height='300'
crop='1'
group='group_img6'
type='image'
/>

</cms:template>
Code: Select all
<cms:pages masterpage='portfolio.php' >
<cms:set count_image='0' />

          <cms:repeat count='6' startcount='1' >
                    <cms:if "image_<cms:show k_count />" >
                            <cms:incr count_image />
                    </cms:if>
        </cms:repeat>

        <cms:show count_image /><!-- here is your prepared number of set images -->

<!-- blog post content -->

</cms:pages>


Please, report upon testing this code.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
@trendoman,

Your approach is sound but the following statement will always evaluate to 'true' -
Code: Select all
<cms:if "image_<cms:show k_count />" >

Reason is that after <cms:show k_count /> is resolved, the statement becomes -
<cms:if "image_1" >
<cms:if "image_2" >
<cms:if "image_3" >
..
where we are simply testing if the string is true (which is always the case and hence answer is true).

What you are actually looking to test is if the *variable* with that name has any value (note there are no quotes) -
<cms:if image_1 >
<cms:if image_2 >
<cms:if image_3 >
..

For that we'll have to use <cms:get> that can take a string as a variable's name (http://docs.couchcms.com/tags-reference/get.html).

Your modified code can now become -
Code: Select all
<cms:set count_image='0' />

<cms:repeat count='6' startcount='1' >
    <cms:if "<cms:get "image_<cms:show k_count />" />" >
        <cms:incr count_image />
    </cms:if>
</cms:repeat>

<cms:show count_image /><!-- here is your prepared number of set images -->

That said, I think a better approach for the OP would have been to use repeatable_regions for the images instead of six individual images.

Hope it helps.
Yup. Thank you! :)
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Perfect, thank you soo mutch :)
9 posts Page 1 of 1