Search code examples
phpphpbb3

Making a row clickable to take you to a link


I've made some CSS modifications to it already and now I need to make one programming modification. I'm a C# guy so this PHP is throwing me a little curve ball.

Here is the part I would like to modify:

<li class="row">
            <!-- EVENT forumlist_body_forum_row_prepend -->
            <dl class="icon {forumrow.FORUM_IMG_STYLE}">
                <dt title="{forumrow.FORUM_FOLDER_IMG_ALT}">
                    <!-- IF forumrow.FORUM_IMAGE --><div class="forum-image">{forumrow.FORUM_IMAGE}</div><!-- ENDIF -->
                    <a href="{forumrow.U_VIEWFORUM}" class="icon-link"></a>

                    <!-- IF .forumrow.subforum and forumrow.S_LIST_SUBFORUMS -->
                    <div class="dropdown-container dropdown-button-control">
                        <span title="{forumrow.L_SUBFORUM_STR}" class="dropdown-trigger"></span>
                        <div class="dropdown hidden">
                            <div class="dropdown-contents">
                            <!-- EVENT forumlist_body_subforums_before -->
                            <strong>{forumrow.L_SUBFORUM_STR}{L_COLON}</strong>
                            <!-- BEGIN subforum -->
                                <a href="{forumrow.subforum.U_SUBFORUM}" class="subforum<!-- IF forumrow.subforum.S_UNREAD --> unread<!-- ELSE --> read<!-- ENDIF -->" title="<!-- IF forumrow.subforum.UNREAD -->{L_UNREAD_POSTS}<!-- ELSE -->{L_NO_UNREAD_POSTS}<!-- ENDIF -->">{forumrow.subforum.SUBFORUM_NAME}</a>
                            <!-- END subforum -->
                            <!-- EVENT forumlist_body_subforums_after -->
                            </div>
                        </div>
                    </div>
                    <!-- ENDIF -->
                    <div class="list-inner">
                        <a href="{forumrow.U_VIEWFORUM}" class="forumtitle">{forumrow.FORUM_NAME}</a>
                        <span class="forum-description">{forumrow.FORUM_DESC}</span>
                        <!-- IF forumrow.MODERATORS -->
                            <!--<br /><span class="forum-moderators"><strong>{forumrow.L_MODERATOR_STR}{L_COLON}</strong> {forumrow.MODERATORS}</span>-->
                        <!-- ENDIF -->
                    </div>
                </dt>

                <!-- IF forumrow.CLICKS -->
                    <dd class="redirect"><span>{L_REDIRECTS}{L_COLON} {forumrow.CLICKS}</span></dd>
                <!-- ELSEIF not forumrow.S_IS_LINK -->
                    <dd class="forum-stats<!-- IF forumrow.S_UNREAD_FORUM --> unread<!-- ENDIF -->"><span>
                        <!-- IF forumrow.LAST_POST_TIME -->(<dfn>{L_TOPICS}{L_COLON}</dfn> {forumrow.TOPICS} | <dfn>{L_POSTS}{L_COLON}</dfn>{forumrow.POSTS})
                        <!-- IF not S_IS_BOT --><a href="{forumrow.U_LAST_POST}" title="<!-- IF forumrow.S_UNREAD_FORUM -->{L_UNREAD_POSTS}<!-- ELSE -->{L_NO_UNREAD_POSTS}<!-- ENDIF -->">{LAST_POST_IMG}</a><!-- ENDIF --><!-- ELSE -->{L_NO_POSTS}<!-- ENDIF -->
                        <!-- EVENT forumlist_body_last_post_title_prepend -->
                    </span></dd>

                    <dd class="mcp-status"><span>
                        <!-- IF forumrow.U_UNAPPROVED_TOPICS -->
                            <a href="{forumrow.U_UNAPPROVED_TOPICS}">{UNAPPROVED_IMG}</a>
                        <!-- ELSEIF forumrow.U_UNAPPROVED_POSTS -->
                            <a href="{forumrow.U_UNAPPROVED_POSTS}">{UNAPPROVED_POST_IMG}</a>
                        <!-- ENDIF -->
                        </span>
                    </dd>
                <!-- ENDIF -->
            </dl>
            <!-- EVENT forumlist_body_forum_row_append -->
        </li>

I would like if the "row" is clicked for it to take you to the forum. Right now only if the title/header is clicked will it take you to the forum.

Which I believe is this line:

<a href="{forumrow.U_VIEWFORUM}" class="icon-link"></a>

Here is a demo of how the default template works:

https://www.phpbb.com/customise/db/style/pbtech/demo/3.1 The only difference I have made from the demo is those forum "blocks" are now changed to take up 100% width instead of 33.3%. I'd like it so if you click anywhere on the forum "block/row" it takes you to the forum.


Solution

  • This cannot be achieved with PHP. It could be achieved with a small JavaScript snippet on the front end.

    <script type="text/javascript">
    $(document).ready( function(){
    
        $("li.row").click( function(){
            var anchor = $(this).find("a:first");
            anchor.trigger("click"); // OR
            window.location = anchor.attr("href");
        });
    });
    </script>
    

    What this does is attaches an event handler to any clicks on li.row. It finds the link within and either triggers click to it, or uses its href property to change browser window location URL.

    This requires a JavaScript library called jQuery which appears to already be in use on your demo template. The code block above would need to be included BELOW the <script> include tag for jQuery.