Display number of views at right of a post title ? (General)

by Ron @, Thursday, January 11, 2024, 11:41 (107 days ago)

Hi, is there a quite easy way to paste some code in order to display between "( )" the number of views of a post just after its name in the forum homepage of list of posts, please ?

Thank you :-)

Avatar

Display number of views at right of a post title? (also @Micha)

by Auge ⌂, Thursday, January 11, 2024, 14:19 (107 days ago) @ Ron

Hello

[edit]
Attention: I had to correct the code for the places, where I inserted the view numbers from ($data.$element.views) to ({$data.$element.views}) at all occurences.
[/edit]

is there a quite easy way to paste some code in order to display between "( )" the number of views of a post just after its name in the forum homepage of list of posts

It's no "easy" way but it's quite possible to apply this change. First things first.

You want to display the number of views for every single entry beside it's subject on the main view pages? The term "main views" means (to me) that these are the views with the listing of all threads (on the current page). If that's, what you mean, you'll need to dig into the source code. You'll have to check a few SQL-queries and the PHP code in one(?) file as well as to change one or two template files.

Everything, I am about to describe refers to the latest stable version 20220803.1.

1. The setting for activating the view counting exists and is available in the advanced settings page with the name count_views.
2. In the script file includes/index.inc.php the query for collecting the data of the thread entries to build the thread tree get requested beginning with line 80. This includes also the number of counted views (column views).
3. Beginning with line 100 of the file includes/index.inc.php the script stores the number of views for a forum entry in the variable $data['views'] if the setting count_views is activated.
4. The data of the entries, stored in $data, will be copied to the variable $data_array in line 130 of includes/index.inc.php and applied to the template engine object in line 229 of includes/index.inc.php. There the data is accessible under the variable name $data again.
5. In the code line 274 and 275 the script loads one of the both possible templates index_table.inc.tpl or index.inc.tpl.

Please check in a first step, if the first five points are valid in your installation. If so, let's go on with the next steps. It might be a good idea to wait until Micha has checked and approved my proposal.

In the next steps I refer to the template themes/default/subtemplates/index.inc.tpl. The steps for the template themes/default/subtemplates/index_table-inc.tpl are generally the same even the code can vary a little bit.

6. In line 44 the list item for a forum entry gets connected. The code line is confusing because of all the different parts and their possible cases (especially applying the classes to the list item itself is a horrible bunch of code 😱). The place, we are interested in, is in the section {if $data.$element.no_text} <img class="no-text" src="{$THEMES_DIR}/{$theme}/images/no_text.png" title="{#no_text_title#}" alt="{#no_text_alt#}" width="11" height="9" />{/if} - <strong>{if $data.$element.user_type==2} and there exactly the space between the {/if} and the dash {/if} -.
7. With the additional code {if $data.$element.views and $data.$element.views > 0} ({$data.$element.views}){/if} it is possible to display the number of views of a forum entry. The necessary requirements: the element views must exist ({if $data.$element.views ...) and its value must be greater than 0 (... and $data.$element.views > 0}).

The resulting code in the relevant section of the template file:


{if $data.$element.no_text} <img class="no-text" src="{$THEMES_DIR}/{$theme}/images/no_text.png" title="{#no_text_title#}" alt="{#no_text_alt#}" width="11" height="9" />{/if}{if $data.$element.views and $data.$element.views > 0} ({$data.$element.views}){/if} - <strong>{if $data.$element.user_type==2}

In the template the relevant section looks a bit different with {if $data.$element.no_text} <img class="no-text" src="{$THEMES_DIR}/{$theme}/images/no_text.png" title="{#no_text_title#}" alt="[ {#no_text_alt#} ]" width="11" height="9" />{/if}<span id="p{$data.$element.id}" class="tail">. I would assume that the relevant place is between {/if} and <span id...

So here the change would resulting in the following code:


{if $data.$element.no_text} <img class="no-text" src="{$THEMES_DIR}/{$theme}/images/no_text.png" title="{#no_text_title#}" alt="[ {#no_text_alt#} ]" width="11" height="9" />{/if}{if $data.$element.views and $data.$element.views > 0} ({$data.$element.views}) {/if}<span id="p{$data.$element.id}" class="tail">

Please note the additional space after the closing bracket of the view number (({$data.$element.views}) {/if} versus ({$data.$element.views}){/if} in the code for index.inc.tpl). It is necessary to separate the view number from the surrounding elements.

Please ask further questions if you are not sure at any point or if you have additional or different requirements.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

Display number of views at right of a post title? (also @Micha)

by Ron @, Thursday, January 11, 2024, 20:18 (107 days ago) @ Auge

Wow, thanks !!!!!
Will try

Avatar

Display number of views beside subjects? A clarification

by Auge ⌂, Tuesday, January 16, 2024, 11:29 (102 days ago) @ Ron

Hello

A clarification afterwards. The first five points of my recipe are intended for checking the current code of your installation. These points does not contain any code change with the exception, your code is different from the code released as version 20220803.1.

The possible code changes are starting with point 6.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

Avatar

Display number of views at right of a post title? (also @Micha)

by Micha ⌂, Monday, January 15, 2024, 19:10 (103 days ago) @ Auge

Hi,

It might be a good idea to wait until Micha has checked and approved my proposal.

No, it isn't. At the moment, I haven't time to check the code. So, please go ahead - and make backups!

/Micha

P.S. Have you deleted my post?!?

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

Avatar

Display number of views at right of a post title?

by Auge ⌂, Tuesday, January 16, 2024, 11:23 (102 days ago) @ Micha

Hello

It might be a good idea to wait until Micha has checked and approved my proposal.


No, it isn't. At the moment, I haven't time to check the code.

Ok.

So, please go ahead - and make backups!

👍

P.S. Have you deleted my post?!?

I am not aware of deleting any posts in the latest weeks beside of obvious spam. Especially I did not delete any post here in this thread.

--
Trenne niemals Müll, denn er hat nur eine Silbe!

Avatar

Display number of views at right of a post title?

by Micha ⌂, Tuesday, January 16, 2024, 11:49 (102 days ago) @ Auge

Hi,

P.S. Have you deleted my post?!?


I am not aware of deleting any posts in the latest weeks beside of obvious spam.

I think I made a mistake. I'm sorry for the confusion.

All the best
Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

RSS Feed of thread