Asked  8 Months ago    Answers:  5   Viewed   41 times

I want to add a numberic pagination to a page with its child pages. This is the pagination I would want to create (from bootstrap):

<nav>
  <ul class="pagination">
    <li>
      <a href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
    <li>
      <a href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </ul>
</nav>

And this is my code:

<!-- block -->
<div class="row grid events-block">

    <?php
    $parent = $post->ID;
    // query_posts('posts_per_page=15&post_type=page&post_parent='.$parent);
    query_posts(array('posts_per_page'=>'1', 'post_type' => 'page', 'post_parent' => $parent, 'paged' => get_query_var('paged')));
        while (have_posts()) : the_post();
    ?>

    <!-- item -->
    <div class="grid-item col-md-6 col-sm-6 col-xs-12 event-item">

        <div class="date-box">
            <?php echo $event_dates; ?>
        </div>

        <div class="event-item-text-box">
            <div class="event-item-text-inner-box">
                <h3 class="heading-item"><a href="#" target="_blank"><?php the_title(); ?></a></h3>
                <p><?php the_excerpt(); ?></p>
            </div>
        </div>

    </div>
    <!-- item -->
     <?php endwhile; ?>

     <?php
     // Reset the post to the original after loop. otherwise the current page becomes the last item from the while loop.
     // https://codex.wordpress.org/Function_Reference/wp_reset_query
     wp_reset_query();
     ?>

</div>
<!-- block -->

<?php $args = array(
    'base'               => '%_%',
    'format'             => '?paged=%#%',
    'total'              => 1,
    'current'            => 0,
    'show_all'           => false,
    'end_size'           => 1,
    'mid_size'           => 2,
    'prev_next'          => true,
    'prev_text'          => __('« Previous'),
    'next_text'          => __('Next »'),
    'type'               => 'plain',
    'add_args'           => false,
    'add_fragment'       => '',
    'before_page_number' => '',
    'after_page_number'  => ''
); ?>

<?php echo paginate_links( $args ); ?>

But I can't get it working. Any ideas what I have missed?

 Answers

11

Pagination Like : Prev 1 2 3 Next

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$data= new WP_Query(array(
    'post_type'=>'YOUR_POST_TYPE', // your post type name
    'posts_per_page' => 3, // post per page
    'paged' => $paged,
));

if($data->have_posts()) :
    while($data->have_posts())  : $data->the_post();
            // Your code
    endwhile;

    $total_pages = $data->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>

Could you please try above code? I think it's helpful for you.

Wednesday, March 31, 2021
 
juanrpozo
answered 8 Months ago
35

Compare an already hashed password with its plain-text string, Here is the example.

<?php
$wp_hasher = new PasswordHash(8, TRUE);

$password_hashed = '$P$B55D6LjfHDkINU5wF.v2BuuzO0/XPk/';
$plain_password = 'test';

if($wp_hasher->CheckPassword($plain_password, $password_hashed)) {
    echo "YES, Matched";
} else {
    echo "No, Wrong Password";
}
?>

I guess instead of $user->data->user_pass you need to use $user->user_pass; as per the documentation here https://developer.wordpress.org/reference/functions/get_user_by/

I am only guessing because I don't know what print_r($user); returns

Hope it helps !

Saturday, May 29, 2021
 
Troncoso
answered 5 Months ago
69

The regex you have isn't going to match properly, it's missing several things. I've changed and simplified it a bit, so if the structure of the unordered list isn't the same every time you may need to modify this. Here is the regex updated in the function:

function addlink_replace($string) {
    $pattern = '/<ul(.*?)class="slides"(.*?)<img(.*?)src="(.*?)"(.*?)>(.*?)</ul>/is';
    $replacement = '<ul$1class="slides"$2<a href="$4"><img$3src="$4"$5></a>$6</ul>';
    return preg_replace($pattern, $replacement, $string);
}

Basically this will match any unordered list that has the class slides, followed by anything up to an image tag, it will capture anything before the source attribute, it will capture the image source itself, anything in the image tag after the source attribute, then anything up to the closing tag of the unordered list.

The replacement will be the same string, but with the anchor tag around the image with the href attribute the same as the image src.

I made a sample output of this on regex101, there is a detailed explanation in the right side column of what it's matching.

Saturday, May 29, 2021
 
tiny
answered 5 Months ago
62

The Bootstrap 4 grid row>col-* aren't designed to be used inside the Navbar. Here is the supported content. Now that Bootstrap 4 uses flexbox, it's much easier to align Navbar content without using the grid row>col-*.

If you want a Navbar with logo and 2 rows, see this answer:
Bootstrap 4 navbar with 2 rows

<nav class="navbar navbar-expand navbar-dark fixed-top bg-dark">
    <div class="container">
        <h1 class="mb-0"><a href="#">Logo</a></h1>
        <div class="d-flex flex-column flex-wrap" id="navbarCollapse">
            <span class="navbar-text ml-auto py-0 px-lg-2">(00) 1234 5678</span>
            <ul class="navbar-nav mb-auto mt-0 ml-auto">
                <li class="nav-item active">
                    <a class="nav-link py-0" href="#">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link py-0" href="#">Product</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link py-0" href="#">Company</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link py-0" href="#">Blog</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Examples:

Basic Navbar with 2 rows: https://www.codeply.com/go/ilJBKjJsEy

Responsive Navbar with 2 rows: https://www.codeply.com/go/DsfePuoZy0

The 2nd example collapses into a mobile stacked menu on small screens that can be toggled using the hamburger icon. Use the flexbox and spacing utility classes to position elements as desired. There are many ways to achieve what you want: https://www.codeply.com/go/pGE8fTf9dM

Saturday, June 26, 2021
 
zIs
answered 4 Months ago
zIs
86

The easiest would be to use one container and put all the contetn items in it, then equal their height via js like that.

PHP

<?php query_posts('posts_per_page=9');while (have_posts()) : the_post();?>
    <div class="col-sm-4 blog-post thumb">
        <?php get_template_part('templates/content', get_post_format()); ?>
    </div>
<?php endwhile?>

JS:

function equalHeight(group) {    
    tallest = 0;    
    group.each(function() {       
        thisHeight = $(this).height();       
        if(thisHeight > tallest) {          
            tallest = thisHeight;       
        }    
    });    
    group.each(function() { $(this).height(tallest); });
} 

$(document).ready(function() {   
    equalHeight($(".thumb")); 
});

If thats no option, you could do sth. like that:

PHP

<div class="row">
    <?php 
        $count=0; 
        query_posts('posts_per_page=9'); 
        while (have_posts()) : the_post(); 
    ?>
    <div class="col-sm-4 blog-post thumb">
        <?php get_template_part('templates/content', get_post_format()); ?>
    </div>
    <?php 
        $count++; 
        if($count == 3 || $count == 6 ) echo '</div><div class="row">';
        endwhile;
    ?>
</div>
Thursday, July 29, 2021
 
shin
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share