Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with dynamic button positioning


  • fastk9dad
    Participant

    @fastk9dad

    I am looking to make my “New Topic” button below follow the pagination, by that I mean if there is only one page and the pagination links don’t exist I want the “New Topic” button to appear all the way to the right. If there is pagination I want it to sit at it’s left most side like my example below. Right now I’m just placing it there in a static position which means on pages with no pagination it’s just floating in space.

    Example position:
    button position

    This is the static code I’m using for the button:

    #bbpress-forums .new-topic {
        margin-top: -41px;
        margin-right: 80px;
        float: right;
    }
Viewing 10 replies - 1 through 10 (of 10 total)

  • Robin W
    Moderator

    @robin-w

    do you know how to put functions into your theme’s function file?


    fastk9dad
    Participant

    @fastk9dad

    Yes. I have a full child theme set up with a functions.php and modified bbpress templates as well.


    fastk9dad
    Participant

    @fastk9dad

    Just following up, I have a function I can use to put the button on the page instead of changing the content-single-forum.php page in my child theme, but it still puts it outside the bbp-pagination div so I run in to the same styling issues. I’m not sure what function to use if I want to insert something into that area.


    Robin W
    Moderator

    @robin-w

    can you give me the function you are currently using to produce this button.


    fastk9dad
    Participant

    @fastk9dad

    Hrmm, I replied last night and it looks to be gone now. Not sure if I’ve gotten moderated but I’ll put my response here again.

    Currently I’m just using this code in the content-single-topic.php template in my child theme.
    <a href="/forums/new-topic/?ForumId=<?php echo bbp_get_forum_id()?>"><div class="new-topic btn">New Topic</div></a>

    I have developed this for use in function.php to replace the above but I get a parsing error right now. It works ok if I don’t try to insert the ForumID so something is wrong with my syntax.

    function pmh_new_topic_btn() {
    	if ( is_user_logged_in() ) {
    		echo '<a href="/forums/new-topic/?ForumId=".$_GET['ForumId'].""><div class="new-topic btn">New Topic</div></a>';
    	}
    }
    add_action('bbp_template_before_topics_loop','pmh_new_topic_btn');

    Regardless of which method I use the resulting code is always placed after the bbp-pagination element and my CSS fu isn’t strong enough to have the button flow/move with the bbp-pagination-links contained within (is it even possible?).

    <div class="bbp-pagination">
    	<div class="bbp-pagination-count">
    		Viewing 3 topics - 1 through 3 (of 3 total)
    	</div>
    	<div class="bbp-pagination-links">
    	</div>
    </div>
    <a href="/forums/new-topic/?ForumId=1486">
            <div class="new-topic btn">New Topic</div>
    </a>

    fastk9dad
    Participant

    @fastk9dad

    I fixed my function above so this works now:

    function pmh_new_topic_button() {
    $forum_id=bbp_get_forum_id();
    
    	if ( is_user_logged_in() ) {
    		echo '<a href="/forums/new-topic/?ForumId='. $forum_id .'"><div class="new-topic btn">New Topic</div></a>';
    	}
    }
    
    add_action('bbp_template_before_topics_loop','pmh_new_topic_button');

    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed


    fastk9dad
    Participant

    @fastk9dad

    Well I fixed the function so it works (displaying the button), but I still don’t know how to get the button into the position I want.


    Robin W
    Moderator

    @robin-w

    untested but try

    add_action('bbp_template_before_pagination_loop','pmh_new_topic_button');


    fastk9dad
    Participant

    @fastk9dad

    Thanks. I gave that a shot but it just put it before the pagination elements, not inside.

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