I have been trying to assign some js files only to their respective pages on my site, instead of loading them everywhere and have been successful apart from with my forum area.
in my functions.php file i have tried the following:
add_action ('wp_print_scripts', 'deregister_forum_scripts');
function deregister_forum_scripts(){
if ( !is_page('forum') (is_page() && in_array( 19306, get_post_ancestors( get_the_ID() ) ) ) ) {
wp_deregister_script('forum-js');
}}
whereby i got the id 19306 from my database by doing:
select ID from wp_posts where post_name = 'forum';
As the page is http://www.apis.de/forum/
The issue is, even if I leave out the second part of the “if” statement (i.e. “is_page()….), it doesn’t work.
I assume this is because my forum is implemented differently to the rest of my site and is not a normal “is_page(….)”.
Can anyone advise here how to target the forum via PHP?
Also, i don’t think i should be using “get_post_ancestors” but “get_page_children“. But that is another topic.
Hello, my skills are too limited to do that. I’ve simply moved it carefully to be visible for all.
Can you please remove all our posts previous posts to clean the topic ?
TO CONCLUDE :
function rew () {
if ( is_user_logged_in() ) {
echo '<p><a href="http://your_url/new-posts"><div class="newposts">Show new posts</div></a></p>' ;
}
else
echo '<p><a href="http://your_url/new-posts"><div class="newposts">Show new posts</div></a></p>' ;
}
Put this into function.php of your child theme
.newposts {
float: left;
background-color:#DD9933;
padding: 5px 6px;
margin:5px 5px 2em 0;
}
.newposts a {
color:#f2f2f2 !important;
border:none;
border-radius:0;
box-shadow: none;
color:#ffffff;
font-size:13px;
}
And put that into your custom style.css. If your button doesnt appear while your loggued or while you’re not, take care of the margin and the padding of the CSS!
You will have to create a new page “new-posts”. Add [bbp-topic-index] to this page to display your topics in order (most recent ones). If you need a more customizable list, install BBP-Style Pack and go to the Shortcodes section.
You can see it now, I put :
.newposts {
float: left;
background-color:#DD9933;
padding: 5px 6px;
margin:0px 5px 2em 0;
}
.newposts a {
color:#f2f2f2 !important;
border:none;
border-radius:0;
box-shadow: none;
color:#ffffff;
font-size:13px;
Thank you for input
I found what caused issue.
the call for visual composer footer in a shortcode was:
apply_filters( ‘the_content’, $the_post->post_content );
The apply of do_shortcode to $the_post->post_content before echo fixed the text format output of shortcodes and footer now works.
Thank you.
so what is that bit of code trying to do ?
I’ve just taken a look at your site
the issue is the css
.newposts {
float: left;
background-color: #DD9933;
padding: 5px 6px;
margin: -65px 5px 2em 0;
}
if you take out the ‘margin: -65px 5px 2em 0;’ then the code is on screen, otherwise it is offscreen
ok, so
1. can you post the exact code you are now using
2. can you tell me where your are putting this code?
That’s right! And when I check on the source code in a browser while non loggued, I can clearly see the code with the button.
that’s no problem, and yes it doesn’t look like the issue is in there.
so the original code works fully with logged in, but not at all with non logged in- yes?
It detect the folder “templates” in the theme. (orange color)
CSS part is green.
I’ve installed a fresh version of my original theme + created a new child theme.
If I modify the function.php of the original theme, all works well.
If I add my content to the function.php of my new child theme, nothing appears…
I can’t get the new child theme working, like my current one.
Anyway, strange thing is that I can see the piece of code when I inspect the source with a browser :
<div class="bbp-breadcrumb"><p><a href="xxx" class="bbp-breadcrumb-home"><span class="bsp-home-icon"></span></a> <span class="bbp-breadcrumb-sep">›</span> <span class="bbp-breadcrumb-current">Forum</span></p></div>
<p><a href="lasts-topics-posts/"><div class="newposts">Show new posts</div></a></p>
<ul id="forums-list-0" class="bbp-forums">
It seems to be hidden by something..
ok, just tested and my original code works fine on my test site.
it could be a theme or plugin issue
Themes
As a test switch to a default theme such as twentytwenty, and see if this fixes.
Plugins
If that doesn’t work, also deactivate all plugins apart from bbpress and see if this fixes. if it does, re-enable one at a time to see which is causing the error.
If you cannot do this to your site (say because it is live) then use the ‘troubleshooting’ features of this plugin to let you test without affecting other users
Health Check & Troubleshooting
Then come back
Thanks Robin but I don’t think this is the easiest way for me to make this button available for users and guests.
When [bbp-topic-index] is available for all (no restrictions in my board), I just need to put my button available for everyone.
I’ve tried this :
add_action ('bbp_template_before_forums_index' , 'rew' ) ;
function rew () {
if(!is_user_logged_in()) return;
echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ;
}
and
function rew () {
if ( is_user_logged_in() ) {
echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ;
}
else
echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ;
}
But doesnt works..
Hello Robin, once again your advice rocks!
Here is my result :
Function.php of my child theme :
add_action ('bbp_template_before_forums_index' , 'rew' ) ;
function rew () {
echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ;
}
and my css :
.newposts {
float: left;
background-color:#DD9933;
padding: 5px 6px;
margin:-65px 5px 2em 0;
}
.newposts a {
color:#f2f2f2 !important;
border:none;
border-radius:0;
box-shadow: none;
color:#ffffff;
font-size:13px;
}
@media(max-width:580px) {
.newposts {
float: right;
background-color:#DD9933;
padding: 5px 6px;
margin:-15px 0px 2em 0;
}
.newposts a {
color:#f2f2f2 !important;
border:none;
border-radius:0;
box-shadow: none;
color:#ffffff;
font-size:13px;
}
}
I had to make a custom CSS to get it responssive with mobile phones.
I still got a little issue which is that my buton dn’t appear when you’re not connect, I need to fix that!
there is a hook in the content-archive-forum.php file you can use
bbp_template_before_forums_index
so
add_action ('bbp_template_before_forums_index' , 'rew' ) ;
function rew () {
//your code here eg
echo 'hello' ;
}
just tried a shortcode in the footer of my test site running twentyten, and it works on both bbpress and non bbpress pages using the text widget
The function is_bbpress() is for any page of bbpress
Does not matter, it is account or forum or topic… on all pages…
Footer is built with visual composer…
If i use a shortcode to display forum index, the footer works fine. as soon i click into form:
https://<domain>/forums/forum/<forum name>/ footer breaks
https://<domain>/forums/topic/<topic name>/ footer breaks
https://<domain>/forums/user/<user name>/ footer breaks
It becomes as: [vc_row full_width=”stretch_row” css=”…” ….]…….[/vc_row]
Looks like on those page the WordPress function do_shortcode is disabled/unactivated…
Do this make more clear on what pages and what happens with footer?
can you give an example – eg of a footer shortcode that breaks and what bbpress page
Hi
This is a major issue with bbpress and I could not find a resolution to it. I found couple of similar requests but no one have full resolution.
Basically, if page can be recognized as is_bbpress() true than the footer shortcodes breaks.
How to fix that? Is there some patch?
I dit the trick with some CSS improvments :
width: 100px;
padding: 2px;
@media(max-width:580px) {
div#bbpress-forums {
overflow: visible !important;
}
#bbpress-forums span.bbp-admin-links a,
#bbpress-forums span.bbp-admin-links
{
width: 100px;
padding: 2px;
color: grey;
}
}
No worries Robin, I appreciate you are trying to help!
Your question raises a very valid point – I didn’t think it could be related. I currently have my Forums page set up like this:
Recent topics
[bbp-topic-index]
All topics
[bbp-forum-index]
sorry, working across many things and missed that.
so that page is made up of ‘all topics’ and ‘recent topics’ – are these shortcodes on a page, or how is this page content created?
Oh and I forgot to mention that I did test it by deactivating plugins and changing theme. The issue persists, when the shortcode is used.
Is AJAX enabled for the buttons if the Subscribe and Favorite buttons are used within the Replies shortcode?
Many thanks I will give it a try. However there is so many things that is not working properly so its starting to become a case for some freelancer site. I dont really know what I am doing 🙂
I read your guide: https://codex.bbpress.org/step-by-step-guide-to-setting-up-a-bbpress-forum/
But I cant get the forum to display using method 1 in the above guide. And method 2 is the one I have done from the start but cant get to look the way i want.
If the plugin “bbp style pack” fix the design, there is still the issue with weird menus and different urls within the forum etc. Could it be that I created the forum before changing WP-theme? Could it help to remove BB-press and then reinstall it from the ground up?