Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add a custom button

  • @akira010203

    Participant

    Hello,

    In order to implement my board, I want to put a link a the top right of my forum main page which will redirect to [bbp-topics-index] like that :

    I’m thinking using <span onclick=”window.location.href=’www.google.com’;”>text</span>
    but I don’t know where to put it in my child theme.

    Can someone help me please ?

    Thanks!

Viewing 25 replies - 1 through 25 (of 27 total)
  • @robin-w

    Moderator

    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' ;
    }

    @akira010203

    Participant

    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!

    @neon67

    Participant

    Thank you for writing the final solution – it’s useful for everyone)

    @robin-w

    Moderator

    great – glad you are fixed !!

    @akira010203

    Participant

    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..

    @robin-w

    Moderator

    that button would show in all cases – at a guess I’d say you have caching software that might need resetting.

    @akira010203

    Participant

    I don’t have anything like that.

    I only got few plugins linked to bbpress (bbp Style pack, unread posts, etc..).

    @robin-w

    Moderator

    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

    @akira010203

    Participant

    The issue comes from my theme, maybe too much modifications.

    I really don’t know how to solve this instead of using another method to create my button..

    @robin-w

    Moderator

    so if you go to this tab

    dashboard>settings>bbp style pack>Not working ?

    and look at no. 2 – are there any files listed in there?

    @akira010203

    Participant

    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">&rsaquo;</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..

    @robin-w

    Moderator

    ok, does my style pack list any files changed in your theme under section 2?

    @akira010203

    Participant

    Sorry it’s in french :

    @robin-w

    Moderator

    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?

    @akira010203

    Participant

    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.

    @robin-w

    Moderator

    ok, so

    1. can you post the exact code you are now using
    2. can you tell me where your are putting this code?

    @robin-w

    Moderator

    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

    @akira010203

    Participant

    Once again you are right..

    So now I need to double my CSS for loggued and non loggued users.. Any idea ? 🙂

    @robin-w

    Moderator

    so what is that bit of code trying to do ?

    @akira010203

    Participant

    you mean my trick with the margin on the CSS ?

    @robin-w

    Moderator

    yes

    @akira010203

    Participant

    With CSS :

    Without CSS :

    I was trying to align it with the Mark all as read button…

    @robin-w

    Moderator

    not sure I can see from that what the difference is – can you onky take out the margin line, so the background etc. is still there

    @akira010203

    Participant

    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;

    @akira010203

    Participant

    Guests view :

    Loggued users :

Viewing 25 replies - 1 through 25 (of 27 total)
  • You must be logged in to reply to this topic.
Skip to toolbar