WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 08.10.2021 18:13:36

losttrip
Mitglied

Only add link attributes if there is a long description

Because I have styles associated with Title text and Preview image links (default and hover effects), even when there is no long description, these link styles are visible on the linked elements (which is confusing to users, and just looks strange).  See image for example:

no link

Is there a way to set up NWI to only place the link properties (a href ) on these elements when there is actually a link necessary?

I was given this working solution to hide the a href when there is no long description or gallery images in NIA:

<div class="mod_nwi_teaserpic">
     {% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}
     <a href="{{ news.LINK }}">{% endif %}<img src="{{ news.IMAGE }}" />{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}</a>{% endif %}
</div>
{% endif %}
<div class="mod_nwi_teasertext">
     {% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}
     <a href="{{ news.LINK }}">{% endif %}<h3>{{ news.TITLE }}</h3>{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}</a>{% endif %}

Is there a similar solution to achieve this in NWI?

Here is my NWI Post Loop:

<div class="mod_nwi_group">
    <div class="mod_nwi_teaserpic">
        <a href="[LINK]">[IMAGE]</a>
    </div>
    <div class="mod_nwi_teasertext">
       <a href="[LINK]"><h3>[TITLE]</h3></a>
        <div class="mod_nwi_metadata">Published [PUBLISHED_DATE]</div>
            <div class="mod_nwi_shorttext">
                [SHORT]
            </div>
            <span style="visibility:[SHOW_READ_MORE];"><a href="[LINK]">[TEXT_READ_MORE]</a></span>
        </div>
    </div>
    <div class="mod_nwi_spacer"><hr /></div>

Thank you.

Beitrag geändert von losttrip (08.10.2021 22:06:42)

Offline

#2 09.10.2021 07:54:08

florian
Administrator

Re: Only add link attributes if there is a long description

Good point.
There are only some small changes to the modules/news_img/functions.inc.php needed:

Find 2 times

$anz_post_img = count($images);
            // no "read more" link if no long content
            if ( (strlen($post['content_long']) < 9) && ($anz_post_img < 1)) {
                $post['post_link'] = '#" onclick="javascript:void(0);return false;" style="cursor:no-drop;';
            }

and change it to

$anz_post_img = count($images);
$post_href_link = 'href="'. $post['post_link'].'"';
            // no "read more" link if no long content
            if ( (strlen($post['content_long']) < 9) && ($anz_post_img < 1)) {
                $post['post_link'] = '#" onclick="javascript:void(0);return false;" style="cursor:no-drop;';
		$post_href_link = 'href="'. $post['post_link'].'"';
            }

Find

'LINK'            => $post['post_link'],

and after this, add

'HREF'			  => $post_href_link,

In the page settings, you can use now

<a [HREF]>[IMAGE]</a>

So the <a> tag is generated, but not clickable.

This will be available in the next version of NWI too.

Beitrag geändert von florian (09.10.2021 07:55:25)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#3 04.02.2022 02:44:51

losttrip
Mitglied

Re: Only add link attributes if there is a long description

Sorry it has taken me so long to test this out.

I installed NWI version 5.0.13 which from my understanding has this functionality included.

I changed my code for the preview image to:

<a [HREF]>[IMAGE]</a>

The results on the front end are that the image css hover effects still trigger, because there is still the <a> tag attributed to the image.  The only noticeable change from the old version is that instead of the red "no drop" cursor on hover, the cursor on hover of the image is the "pointer":

href change

I'm sorry to report, this does not accomplish what I was looking for:

losttrip schrieb:

Is there a way to set up NWI to only place the link properties (a href ) on these elements when there is actually a link necessary?

If there is no details or gallery, I do not want there to be <a> tags on the title or preview image.  Therefor there will be no confusing hover effects on these elements.

As I said, the following NIA code accomplishes this result:

{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}
     <a href="{{ news.LINK }}">{% endif %}<img src="{{ news.IMAGE }}" />{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}</a>{% endif %}

Is there a way to accomplish this with NWI?

---

Also, I though I should point out that although the install succeeded:
6d1760ee32f0889a20a92267106ca80e.png

... the Add-Ons module details still show 5.0.7:
7f6e4826819ff6cc998e68e5ca9b057f.png

Offline

#4 07.02.2022 23:17:19

losttrip
Mitglied

Re: Only add link attributes if there is a long description

Sorry for my wordy posts.  I'll try to simplify my question.

Is there a way to only add the <a> (href) tag IF the post has content.long or gallery images?

Something like this:

   

<div class="mod_nwi_teaserpic">
        <if (news.CONTENT_LONG or news.HASGALLERYIMAGES)><a href="[LINK]"><end if>[IMAGE]<if (news.CONTENT_LONG or news.HASGALLERYIMAGES)></a><end if>
    </div>

    <div class="mod_nwi_teasertext">
       <if (news.CONTENT_LONG or news.HASGALLERYIMAGES)> <a href="[LINK]"><end if><h3>[TITLE]</h3><if (news.CONTENT_LONG or news.HASGALLERYIMAGES)></a><end if>
        </div>

Like I said, the code below accomplishes this in NIA.

{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}
     <a href="{{ news.LINK }}">{% endif %}<img src="{{ news.IMAGE }}" />{% if (news.CONTENT_LONG or news.HASGALLERYIMAGES) %}</a>{% endif %}

But I need the same functionality in NWI.

Offline

#5 08.02.2022 12:29:19

florian
Administrator

Re: Only add link attributes if there is a long description

Please find attached the NWI version 5.0.14 for testing.
I've added two new placeholders, [AOPEN] and [ACLOSE].

Update NWI as usual*. Then, in the post loop settings, replace

 <a href="[LINK]"><h3>[TITLE]</h3></a>

and

 <a href="[LINK]">[IMAGE]</a>

with

[AOPEN]<h3>[TITLE]</h3>[ACLOSE]

and

[AOPEN][IMAGE][ACLOSE]

The complete <a href="foo.php">  and the closing </a> will that way be generated only if there is a long text and/or gallery to that post.

* idk why, but the version shown in the backend is only increased if Add-Ons > Advanced > Reload modules is executed.

Beitrag geändert von florian (08.02.2022 12:29:49)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

losttrip, berny

#6 08.02.2022 17:45:01

losttrip
Mitglied

Re: Only add link attributes if there is a long description

Florian.  Your new version with the added functionality works beautifully.  Thank you so much.

Demo - The top post has long text, the bottom post does not have long text or a gallery.

hover effect only on linked image and text

I do not mean to sound negative or appear to be questioning anyone's logic, I am just curious why this resulting behaviour would not be the preferred default?  Specifically, I am curious what the point is of keeping the <a> href tag present when there is no link (long text or gallery) to go to? ... when doing so further forces the use of javascript to change the cursor appearance on hover?

Please don't feel the need to explain, I am just puzzling out loud.

I'm very grateful for everything you do for those of us who benefit from the joys of using WBCE.  And, on a personal level, above your generous efforts, your kindness and patience are deeply appreciated.

Offline

Fußzeile des Forums

up