0

I am using medusa wordpress theme. I want it only for blog so I want to have newest posts on main page. But in theme option there is no option to change blog layout, so I have to created new page named blog and there via page builder I have added blog and sidebar. In blog settings I have choosen 3 columns blog. Then set it as static home page and it is working fine, but pagination is not working. Pagination is working when there is no static page but then I don't know how to set grid. How can I solve this? I have newest theme and wordpress. Thanks

where should I try to find problem? In wordpress theme file, or wordpress? Or should I try some third party plugin? This is from loop.php...

show_pagination = isset($tw_options['show_pagination']) ? $tw_options['show_pagination'] : true;

if ($show_pagination) {
    pagination();
}
wp_reset_query();
}

theme_functions.php

function pagination() {
global $wp_query;

$pages = $wp_query->max_num_pages;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

if (empty($pages)) {
    $pages = 1;
}

if (1 != $pages) {

    $big = 9999; // need an unlikely integer
    echo "<div class='tw-pagination pagination'>";

    $pagination = paginate_links(
            array(
                'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                'end_size' => 3,
                'mid_size' => 6,
                'format' => '?paged=%#%',
                'current' => max(1, get_query_var('paged')),
                'total' => $wp_query->max_num_pages,
                'type' => 'list',
                'prev_text' => __('&laquo;', 'medusa'),
                'next_text' => __('&raquo;', 'medusa'),
    ));

    echo $pagination;

    echo "</div>";
}
}
  • 1
    If you have written any code for it, only then we can offer our assistance. But if you are asking about functionality of any third party or paid theme then this is something you should ask on their support page. Third party plugins and themes are off-topic here as per the site rules. – Rishabh Oct 18 '16 at 14:40
  • Sry, I have updated my question a little bit. I didn't make any changes in code... When I click on page 2 at the bottom, in url I can see /?paged=2 but contents is still from page 1. I also tried to deactivate all plugins, but still the same problem... so probably theme fix will be needed. My support for this theme is over... I don't want to pay another money for this. I will try some third part plugins I think – vb381 Oct 18 '16 at 15:59
  • It is working fine also for blog page, until I will choose this page as static home page in settings. – vb381 Oct 18 '16 at 17:19
0

If you want to show pagination in home page then it require one change like in following line of your code

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

You need to replace your query variable like paged (get_query_var('paged')) with page because in other pages we use paged but in home page for pagination we have to use page. So just replace above code line with this

 $paged = (get_query_var('page')) ? get_query_var('page') : 1;

See if that works.

UPDATE

To make post list page with pagination from beginning, first you have to make template in your theme and paste following code in there.

<?php
/*
Template Name: Archives 
*/
get_header();
?>
<div style="width:100%; padding:50px;">
    <?php
    $paged = get_query_var('page') ? get_query_var('page') : 1;
    $args = array('post_type' => 'post',
    'posts_per_page' => 10,
    'paged' => $paged
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        ?>
            <li style="list-style:none;">
            <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><font style="color:#666666;"><?php the_title();?></a><span style="/* color: #d9d9d9; */font-size: 12px;">&nbsp;(<?php echo get_the_date('d.m.Y');?>)</span></h3>
        <?php 
        /*****     Thumbnail     ******/
        the_post_thumbnail(
        array(120, 90),    //resolution of thumbnail image
            array(

                'class' => 'Enter_Class',    //CSS Class for thumbnail image if any
                'alt' => 'post thumbnail',   //Alternate text for thumbnail image
                'title' => 'my custom title' //title of thumbnail image
            )
        );
        /*******     Thumbnail Ends   ********/

        /***  Description of post  ***/
        ?> <p> <?php the_excerpt();?> <a href="<?php the_permalink() ?>">Read More</a></p></font>
        </li><hr />
        <?php 
    endwhile; ?>

    <div class="class-name" style="float:left;padding:20px;">
        <?php
        // next_posts_link() usage with max_num_pages
        next_posts_link( 'Older Entries', $loop->max_num_pages );
        ?>
    </div>
    <div class="class-name" style="float:left;padding:20px;">
        <?php
        previous_posts_link( 'Newer Entries' );
        ?>
    </div>
    <?php 
    // clean up after the query and pagination
    wp_reset_postdata(); 
    ?>
</div>
<?php get_footer(); ?>

Few points need to know

  1. With the above code pagination will work only in home page. If you want to show pagination in inner page then you have to make change in one line of above code. If you want to show pagination in inner page or non static front page then look for following line of code

    $paged = get_query_var('page') ? get_query_var('page') : 1;
    

Just replace above line of code with this line

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

The only difference between these lines has already been explain before this updated answer.

  1. You need to make formatting of your post list. Set Divs and classes/IDs inside code to make it look like your previous post list page.

UPDATE

How to add pagination in single.php

To add pagination in single.php, you just need two functions

  1. next_post_link(); To show Next Post link
  2. previous_post_link(); To show previous post link

These functions will display title of posts as link. For example if you show next_post_link(); then whoever the next post in queue, This function will display its title as link of the post And same goes to previous_post_link();. Then your pagination will be look like this

Title of Previous Post          Title of Next Post

How to Show Custom Text Instead of Title of Post as link

If you want to show custom text as link, For example you want your link appear something like this

Next Post          Previous Post

For that you have to specify custom text in function like this

next_post_link('%link', 'Next Post', TRUE);

In the above function custom text Next Post has been shown so the link text will appear as Next Post instead of post title.

Where to add these functions

Whereever you will add these functions in single.php file, pagination will appear there. But as per your single.php file you can add these function below or above comments. For exaple look for following code line in your single.php

<?php comments_template('', true); ?>

This line is responsible for comment box that appear on single post page.

So if you want to add pagination above comment box then add pagination functions above this line <?php comments_template('', true); ?> Like This

next_post_link('%link', 'Next', TRUE);
previous_post_link('%link', 'Prev', TRUE);
<?php comments_template('', true); ?> 

And if you want to show pagination below comment box then add these two functions below this line <?php comments_template('', true); ?>.

And at last don't forget to style your pagination. By style mean Position of next and previous post link. It would be better if you add these functions in saperate DIV like this

<div class="class-name" style="float:left;padding:20px;">  
<?php next_post_link('%link', 'Next Post', TRUE); ?>
</div>
<div class="class-name" style="float:left;padding:20px;">
<?php previous_post_link('%link', 'Previous Post', TRUE); ?>
</div>

Just add above code above or below comment functions and your pagination is ready.

UPDATE

To add post list with pagination in Static Front Page you need to edit your page.php if your static front page is from dashboard -> pages. page.php file is resposible for appearing all page in wordpress and single.php file is for posts detailed page.

To show pagination on static front page you need to use template code that I have shown you earlier in my previously updated answer (Custom template code). Code that you have used earlier in your custom teplate that same code will be use in page.php file to show pagination in static front page.

You need to add that code in your page.php file. But keep in mind if you will add that code in page.php file then pagination will appear in all of your pages in wordpress because page.php file's content are use to show in all pages of wordpress. And you need pagination only in front page. So to show pagination only in front page you need to add one IF condition in that code.

Basically to show pagination in home page only you need one function named as is_home(). Use this function in IF condition like this

If(is_home()){

    enter code of custom teplate here

}

is_home() is use to check that current page is home page or not. If the current page is home page only then template code will run so that pagination will show only in front page.

Where ever you will add this code post list will appear with pagination on that place. To made neccessary changes in apprearance of list you need to understand code completely. So it is strongly recomended that to get you desire page look/appearance you must read all comments and description, only then you can edit code as per your need.

NOTE

In single.php we used this function to show pagination

next_post_link();

And in page.php we used this function for pagination

next_posts_link();

Only difference between these function is that, we use keyword post in function name for single.php and keyword posts is used for page.php.

  • Thank you for the answer but still the same problem, nothing changed :/ – vb381 Oct 19 '16 at 6:28
  • @vb381 Ok then try to do one more change in your code. See updated answer. – Rishabh Oct 19 '16 at 7:12
  • thanks, but still the same problem – vb381 Oct 19 '16 at 13:51
  • Hmm it seems your problem is not present in this code. In that case I can show you different code through which you can make your pagination where ever you want. But that code requires a different page template. Tell me if you are interested in changing your code for pagination then I will show you full working and easier code for it. – Rishabh Oct 20 '16 at 4:18
  • sure, I am interested in – vb381 Oct 20 '16 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.