Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  

Automatic Open Thread List - A guide to finding your variables
   (0 reviews)

Kit the Human
  • IPS is a powerful product. Most of the time, if I need to achieve something, I can do it with page blocks. Sometimes, I just need to alter those page blocks a little bit in order to achieve what I want to achieve.

     

    In this guide, I hope to help guide you through looking for the correct variables and writing a simple if statement. At the end of the guide, you should have a working automatic open thread list.

    Software: Invision Power Services (IPS) 155,145,143,110

PHP and HTML Logic

PHP is also known as PHP: Hypertext Preprocessor. The name gives you a hint into what PHP does. If hypertext is the stuff that web pages are made of, then PHP would be what happens before it is processed. In other words, PHP is server side executed code as opposed client side, which javascript is. So, PHP is code that is executed by your host's server. Javascript is executed by your browser.

 

IPS uses a mix of HTML (your usual <div> <span> etc) and PHP in their templates. They call this, HTML Logic. Because of this, a lot of PHP statements are open to you, though the syntax might be different. If you want to deep dive into PHP, I recommend the guides linked to this one at the bottom of the page.

 

IF Statements

The bulk of my modifications are done with if statements. An if statement can be thought of as a sentence:

 

IF thread has no replies, display thread link.

 

In HTML logic:

 

{{if ( $topic->posts - 1 ) === 0}}
	Link
{{endif}}

 

The first line is saying, if topic has exactly 0 posts

Second line is saying, link.

Final line closes the if statement.

 

This is basically what we're going to do with our automatic open thread listing!

 

The Block

To get started, we need to do some basic set up.

 

  • Go to Page Management
  • Blocks
  • Create New Block
    • Type: Plugin
    • Plugin: Forums > Topic Feed
    • Click Next
    • Name is whatever makes sense to you
    • Description is optional.
    • Category is whatever (it's for organisational purposes.)
    • Go to Feed Configuration
      • Show on All Devices - I recommend yes. But you can decide whether to hide this on desktop, tablet or mobile with this option.
      • Title: Open Topics (this will display to the user)
      • Forums: Select all of your roleplay forums.
      • Honor Permissions: Yes
      • Status, Pinned, Featured and Visibility are probably all Either but it depends on how you use these features. If for example, you lock threads to indicate that they're archived, you should change that option to Unlocked.
      • Authors: leave empty.
      • Minimum Posts: Any
      • Number to Show: Your choice.
      • From the Last: Your choice.
      • Sort By: I recommend Start Date
      • Sort Direction: If sorting by start date, A - Z.
      • With Tags: open (make sure you get users to set their threads to open with a tag!)
    • Now onto content!
      • Where it says Use this template as-is, change to Use as a base for a custom template

 

The Alterations

Without altering the template, you will have an auto open thread listing by clicking on save now. However, they will remain on the list, even if the thread is on it's second page.

 

So, what we need to do is to check if each thread with the open tag has zero replies. IPS is already searching for each thread tagged with open, so we only need to add the has zero replies bit.

 

Keeping in mind what we did earlier, the statement will be: IF thread has zero replies, display it.

 

The template contains everything we need to do this. So let's dive in!

 

The first line is

 

{{if !empty( $topics ) }}

 

It's saying, if there ARE threads to display, do the following. (Exclamation mark is a not statement). Keep scrolling down and you will find a reference to where you put the block.

 

{{if $orientation == 'vertical'}}

 

If the block is in the sidebar, then do the following.

 

Skip down a couple of lines and you still start to hit the good bit

 

{{foreach $topics as $topic}}

 

Essentially, for every topic, display them individually as the following. Our if statement needs to go inside this foreach statement because we need to individually check every topic.

 

If you scroll down further, you will come across references to the user's photo, how many posts the topic has.... stop there. That's the variable we're looking for.

 

<div class='ipsDataItem_main cWidgetComments'>
  <div class="ipsCommentCount ipsPos_right {{if ( $topic->posts - 1 ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$topic->posts - 1"}'>
    {expression="\IPS\Member::loggedIn()->language()->formatNumber( $topic->posts - 1 )"}
  </div>

 

Phrases like comments, commentcount and posts tells us that we've found our variable. And straight away, we can see that IPS is looking for topics with zero replies already with the following:

 

<div class="ipsCommentCount ipsPos_right {{if ( $topic->posts - 1 ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$topic->posts - 1"}'>

 

Note that there is an if statement saying, IF thread has zero replies, then add ipsFaded as a class.

 

So we can copy and paste the if statement

 

{{if ( $topic->posts - 1 ) === 0}}

 

( === means, exactly the same)

 

and pop it straight after the foreach.

 

{{foreach $topics as $topic}}
	{{if ( $topic->posts - 1 ) === 0}}

 

Make sure to close the endif statement by putting {{endif}} before {{endforeach}}

 

<span class='ipsType_light'>
  {lang="topic_started_date" htmlsprintf="\IPS\DateTime::ts( $topic->mapped('date') )->html()"}
</span>
</p>
</div>
</li>
{{endif}}
{{endforeach}}

 

But what if you wanted to leave it up for more than a few replies to encourage more than one person to reply to an open thread? Let's say our number is six. So we want to skip any open thread with more than six replies.

 

Our statement will be, IF thread has less than or equal to 6 replies.

 

{{if ( $topic->posts - 1 ) <= 6}}

 

<= means less than or equal to.

 

We're very nearly done! If you scroll down towards the bottom, you should see an {{else}} statement. This is in reference to the orientation I mentioned earlier. So, the statement becomes:

 

IF block is in the sidebar do this, ELSE do this.

 

We want to make sure the if statement also applies to the block being in the header, footer, or anywhere else where the block is long. So, same as above. If statement after the foreach and endif before the endforeach.

 

Just want to copy and paste?

 

{{if !empty( $topics ) }}
	<h3 class='ipsWidget_title ipsType_reset'>{$title}</h3>
	{{if $orientation == 'vertical'}}
		<div class='ipsPad_half ipsWidget_inner'>
			<ul class='ipsDataList ipsDataList_reducedSpacing'>
              {{foreach $topics as $topic}}
              {{if ( $topic->posts - 1 ) === 6}}
					<li class='ipsDataItem{{if $topic->unread()}} ipsDataItem_unread{{endif}}{{if $topic->hidden()}} ipsModerated{{endif}}'>
						<div class='ipsDataItem_icon ipsPos_top'>
							{template="userPhoto" group="global" app="core" params="$topic->author(), 'tiny'"}
						</div>
						<div class='ipsDataItem_main cWidgetComments'>
							<div class="ipsCommentCount ipsPos_right {{if ( $topic->posts - 1 ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$topic->posts - 1"}'>{expression="\IPS\Member::loggedIn()->language()->formatNumber( $topic->posts - 1 )"}</div>
							
							<div class='ipsType_break ipsContained'>
								{{if $topic->mapped('featured') || $topic->hidden() === -1 || $topic->hidden() === 1}}
									{{if $topic->hidden() === -1}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{$topic->hiddenBlurb()}'><i class='fa fa-eye-slash'></i></span></span>
									{{elseif $topic->hidden() === 1}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{lang="pending_approval"}'><i class='fa fa-warning'></i></span></span>
									{{endif}}
									{{if $topic->mapped('featured')}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_positive" data-ipsTooltip title='{lang="featured"}'><i class='fa fa-star'></i></span></span>
									{{endif}}
								{{endif}}							
								<a href="{$topic->url()->setQueryString( 'do', 'getNewComment' )}" title='{lang="view_this_topic" sprintf="$topic->title"}' class='ipsDataItem_title'>{$topic->title}</a>
							</div>
							<p class='ipsType_reset ipsType_medium ipsType_blendLinks ipsContained'>
								<span>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span><br>
								<span class='ipsType_light'>{lang="topic_started_date" htmlsprintf="\IPS\DateTime::ts( $topic->mapped('date') )->html()"}</span>
							</p>
						</div>
					</li>
              {{endif}}
          {{endforeach}}
			</ul>
		</div>
	{{else}}
		<div class='ipsWidget_inner'>
			<ul class='ipsDataList'>
              {{if ( $topic->posts - 1 ) === 0}}
				{{foreach $topics as $topic}}
					{template="row" group="global" app="forums" location="front" params="NULL, NULL, $topic, FALSE"}
				{{endforeach}}
              {{endif}}
			</ul>
		</div>
	{{endif}}
{{endif}}

 

A lot of the time, the variables you're looking for are in the template you're working with. Read the template you're working with and find any references to what you're looking for and look for a $variable. I often copy and paste it somewhere odd so that I can check what the variable is actually spitting out. Occasionally, you will need to make some alterations to it in order to make the variable into something that you can use.

 

This guide should hopefully point you in the right direction to finding the variables you need. If you need further assistance, always be sure to ask on the help forums here!


  • Love 1
Sign in to follow this  

Related Guides

  • Arceus

    PHP Fundamentals I

    By Arceus, By Arceus, in Coding,

    Part of a guide series, the PHP Fundamentals guide dives into the very basics of PHP and how it works, designed for people that have never worked with PHP at all, or only very briefly (or people that just want more solid info on the ostensibly easy stuff). This series is designed to build on itself, because PHP is like algebra, you can't just dive straight into the middle. ... well, you could, but it wouldn't be pretty. Fundamentals I covers variables, echo, conditionals, and comparisons.


  • Arceus

    PHP Fundamentals II

    By Arceus, By Arceus, in Coding,

    Part of a guide series, the PHP Fundamentals guide dives into the very basics of PHP and how it works, designed for people that have never worked with PHP at all, or only very briefly (or people that just want more solid info on the ostensibly easy stuff). This series is designed to build on itself, because PHP is like algebra, you can't just dive straight into the middle. ... well, you could, but it wouldn't be pretty. Fundamentals II covers globals and superglobals.


  • Arceus

    PHP Fundamentals III

    By Arceus, By Arceus, in Coding,

    Part of a guide series, the PHP Fundamentals guide dives into the very basics of PHP and how it works, designed for people that have never worked with PHP at all, or only very briefly (or people that just want more solid info on the ostensibly easy stuff). This series is designed to build on itself, because PHP is like algebra, you can't just dive straight into the middle. ... well, you could, but it wouldn't be pretty. Fundamentals III covers arrays.


  • Arceus

    PHP Fundamentals IV

    By Arceus, By Arceus, in Coding,

    Part of a guide series, the PHP Fundamentals guide dives into the very basics of PHP and how it works, designed for people that have never worked with PHP at all, or only very briefly (or people that just want more solid info on the ostensibly easy stuff). This series is designed to build on itself, because PHP is like algebra, you can't just dive straight into the middle. ... well, you could, but it wouldn't be pretty. Fundamentals IV covers functions.




User Feedback

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.