How do exclude the current page from the display when using the Content by Label macro?

I use the Content by Label macro in many situations, but would like the page being viewed to not appear in the list generated. For example, I have 5 pages all related to Resource Management (my label). I want each of the 5 to display a link to the other 4 but not itself. How can I do that?

3 answers

This widget could not be displayed.

There's currently an open feature request for this feature:

https://jira.atlassian.com/browse/CONF-5245

But I did make a workaround until it can be implemented. I included a workaround in the ticket which I will duplicate here. If you include this in your Custom HTML (make sure you copy everything):

<script> $(function() { $('.content-by-label > li > div > a').filter(function() { return $(this).attr('href') === contextPath + '/pages/viewpage.action?pageId=' + AJS.params.pageId || $(this).attr('href') === contextPath + '/display/' + AJS.params.spaceKey + '/' + AJS.params.pageTitle.split(' ').join('+') }).parent().parent().hide().parent().next().filter('div').hide(); }); </script>

Then it will hide the current page from the results of the Content by Label macro. It's not perfect, but it should help.

Stephen

Thanks for the quick response. I have a couple of questions:

  1. being still relatively new to Confluence, how do I implement your script?
  2. in reading the related responses, it sounds like it doesn't work with the Documentation theme (which I'm using with version 5.8.13). Is that true?
  3. Finally, I went to the link you provided for the open link which looks like it was open in 2006, can this really be left open for 10 years? Also, it listed duplicate requests which were marked a completed which seems confusing.

Thanks again 

This widget could not be displayed.

We have the Cloud version of Confluence, so Stephen's solution won't work for us.

If your version of Confluence has CQL filters ("Add a filter" option), you can add a filter for the "With Title" field.

Enter the title of the page with a minus in front of it (e.g., "-My Page").  That's the only way I could figure out how to do it, except that it's a pain to have to explicitly enter the page name.  It would be nice if the macro could take an @self variable or something like it.  (Maybe it can, but I haven't found anything on it.)

Stephen Deutsch Community Champion Mar 08, 2017

I don't think it supports a reference to itself, but one option would be to use the CQL Search macro and simply use a CQL query like 

type=page AND space=spaceKey() AND id!=pageId() AND label=mylabel

and it would automatically generate a list of pages in the current space with that label excluding the current page.

Thanks!  

I'll have to get approval to download and install the plugin, but this looks like the perfect solution for us.

Gabrielle

We can't install Stephen's plugin, but the CQL query macro will take his filter.  Unfortunately, the CQL query macro (in Cloud version anyway) has a fixed report-style output format, with lines, a constant background color, etc., so it can't be used the way Content by Label is. It's not flexible enough. Why doesn't Atlassian listen to users, instead of always coming up with close, but not quite usable solutions.

Hi Gabrielle,

I did write the CQL query macro for Cloud, so I don't see why I couldn't implement a different display style as a new feature. Stay tuned!

(At least I'm assuming you're talking about the CQL Search add-on; it's not very clear from your comment as there is no built in CQL Search macro that I am aware of that allows you to reference the current page/space)

No, I'm talking about a macro called CQL Query. We also have a Search Results macro that uses slightly different syntax:

ConfluenceMacros.pngNeither of these macros allows any user control of output. It's very frustrating.  It would be nice if the Content by Label macro, which does have output control, let us use a CQL query to refine the filter, instead of forcing us to use the crippled "user-friendly" interface.  There's nothing friendly about being stopped from doing very simple things. I found out the "With Title" filter allows only the CONTAINS operator. In other words, there isn't any way to exclude the current page, even by entering each title, because the filter won't accept any form of NOT. You can just filter labels that way.

This widget could not be displayed.

Hi Sandy,

You can filter Content by Label macro table with Table Filter macro to hide the page.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

496 views 7 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you