$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - How to align buttons properly|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How to align buttons properly

matteradmin7PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I am using below code on my function.php file to display two buttons.

function action_after_question_content() {
    if (!is_single()) {
        echo "<a class='button-default' href='".get_the_permalink()."#respond'>See Answer</a>";
        echo "<a class='meta-answer' href='".get_the_permalink()."#comments'>Give Answer</a>";
    }
}

This is working fine but those buttons alignment is not coming properly as you can see on small screen. May I know how can we create different class/div so that they appear smaller and align properly.

Thanks, Avinash

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I am using below code on my function.php file to display two buttons.

function action_after_question_content() {
    if (!is_single()) {
        echo "<a class='button-default' href='".get_the_permalink()."#respond'>See Answer</a>";
        echo "<a class='meta-answer' href='".get_the_permalink()."#comments'>Give Answer</a>";
    }
}

This is working fine but those buttons alignment is not coming properly as you can see on small screen. May I know how can we create different class/div so that they appear smaller and align properly.

Thanks, Avinash

Share Improve this question asked Feb 17, 2019 at 6:07 Avinash PatelAvinash Patel 398 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

first things first lets improve your code:

function action_after_question_content() {
    if (!is_single()) {
        echo "<a class='button-default' href='".esc_url( get_the_permalink() )."#comments'>See Answers</a>";
        echo "<a class='meta-answer' href='".esc_url( get_the_permalink() )."#respond'>Give Answer</a>";
    }
}

Note: We can improve further by getting the numbers of comments, and based on that build the buttons: Ex: If we have a plural numbers of comments we will use "See Answers", if we have one, we will use "See Answer", If we have none, we can display something like "Be the first who answers!"

This will look like:

function action_after_question_content() {
    if (!is_single()) {
        $num_comments = get_comments_number();
        if ( $num_comments ) :
            echo '<a class="button-default btn-puzzle-align" href="' . esc_url( get_the_permalink() ) . '#comments">' . _n( 'See Answer', 'See Answers', $num_comments, 'textdomain' ) . '</a>';
            echo '<a class="meta-answer btn-puzzle-align" href="' . esc_url( get_the_permalink() ) . '#respond">' . __( 'Give Answer', 'textdomain' ) . '</a>';
        else :
            echo '<a class="meta-answer btn-puzzle-align" href="' . esc_url( get_the_permalink() ) . '#respond">' . __( 'Be the first to answer!', 'textdomain' ) . '</a>';
        endif;
    }
}

Where in CSS should look like:

.btn-puzzle-align {
   margin-bottom: 2.5rem;
}

This is just a guessing, the margin-bot could not work but could work depending on the others elements CSS. The code is also untested. Note that you need to change the textdomain to the theme textdomain, and the 2.5rem to what you might need.

Edit:

Also, after writing this, a more good way of doing this is maybe to wrap the buttons in another element:

function action_after_question_content() {
    if (!is_single()) {
        $num_comments = get_comments_number();
        echo '<div class="btn-puzzle-align">';
            if ( $num_comments ) :
                echo '<a class="ap-see" href="' . esc_url( get_the_permalink() ) . '#comments">' . _n( 'See Answer', 'See Answers', $num_comments, 'textdomain' ) . '</a>';
                echo '<a class="ap-give" href="' . esc_url( get_the_permalink() ) . '#respond">' . __( 'Give Answer', 'textdomain' ) . '</a>';
            else :
                echo '<a class="ap-see" href="' . esc_url( get_the_permalink() ) . '#respond">' . __( 'Be the first to answer!', 'textdomain' ) . '</a>';
            endif;
        echo '</div>';
    }
}

And use the padding, which will usually work.

.btn-puzzle-align {
   display: flex;
   justify-content: space-evenly;
   padding-bottom: 2.5rem;
}
.btn-puzzle-align > .ap-see, .btn-puzzle-align > .ap-give{
    float:none;
} 

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far