Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Please See Attached Image Below In Comment

I am using a table to display content on my page.

I am using the twenty eleven theme. I would like to limit the number of rows on the page. i created a custom sidebar template for the page. anyone have any idea how i can limit the number of rows to 20 rows per page and anything beyond that goes to page two. Thus when i add a new row the last row (20) on page 1 becomes the first on page 2. thank you. i create the tables using html in wordpress. am not using a plugin. as you can see in the image i have the page-navi plugin activated in my template (please refer to code for custom template below)

Example of table.

<table border="0">
<tbody>
<tr>
<td> My Content</td>
</tr>
<td>My Content</td>
</tr>
</tbody>
</table>

If anyone can help i will really appreciate. I have basic code knowledge. if you will, please also advise where i put the code.

This is the code for my custom template.

  <?php
/**
 * Template Name: SL Sidebar Template
 * Description: A Page Template that adds a sidebar to pages
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

    <div id="primary">
        <div id="content" role="main">

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'page' ); ?>

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

            <?php endwhile; // end of the loop. ?>


        </div><!-- #content -->
<?php wp_pagenavi(); ?>
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
share|improve this question
    
Please View the Image here Link –  Blair Jun 30 '13 at 14:23
    
Where is that table-- this one <table border="0">...</table>-- in your code? Is it in content-page.php? –  s_ha_dum Jun 30 '13 at 14:55
    
the table is placed on my page in the dashboard. please visit the link in my previous comment to preview how the page looks like. –  Blair Jun 30 '13 at 16:26
    
If you are manually creating and inserting the table via the WordPress post editor, you can't really (reliably) modify it dynamically. @Milo's solution seems like the only viable one. –  s_ha_dum Jun 30 '13 at 16:29
    
if possible please explain how i can modify it dynamically by placing the code in a php file. because my client would like his content in that format. –  Blair Jun 30 '13 at 16:36

2 Answers 2

If you're inserting html directly into the content area, create a separate table for each page and use the <!--nextpage--> quicktag to separate pages.

share|improve this answer
    
i am trying to avoid creating different tables for one page. because the page is the news page. please have a look at the link in my previous comment for a screen shot. –  Blair Jun 30 '13 at 16:28

I guess there is a general missunderstanding in how to achieve the given screenshot dynamically. It looks like you created several posts, copied the result you were given on your index page to a new single page and build a table arround the whole undynamic code? So it seems like you just need a basic newsfeed, limited by 20 posts per page looking like the one your screenshot (square thumbnail, excerpt, date, author)? In general like: http://www.hiphopdx.com/index/news/ . We just need some more information what you try to do. For me it sounds like a simple list of your posts?

Edit:

In case you have created 20+ posts in your WordPress installation try to replace:

<div id="primary">
        <div id="content" role="main">

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'page' ); ?>

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

            <?php endwhile; // end of the loop. ?>


        </div><!-- #content -->
<?php wp_pagenavi(); ?>
    </div><!-- #primary -->

with:

<div id="primary">
        <div id="content" role="main">
           <?php if (have_posts()) : ?>                
                    <table border="0">
                        <tbody>
                            <?php
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $news_query = new WP_Query('posttype=posts&posts_per_page=20&paged=' . $paged);
                            while ($news_query->have_posts()) : $news_query->the_post();
                                ?>
                                <tr>
                                    <td><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></td>
                                </tr>
                            <?php endwhile; ?>
                        </tbody>
                    </table>  
                    <?php wp_pagenavi( array( 'query' => $news_query ) ); ?>                    
        <?php endif; ?>
        </div><!-- #content -->
</div><!-- #primary -->

Now your page template won't get your posts body, which is done by:

<?php get_template_part( 'content', 'page' ); ?> 

Instead, your template runs a new query showing 20 posts per page:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$news_query = new WP_Query('posttype=posts&posts_per_page=20&paged=' . $paged);

telling WP Pagenavi to use your custom query for pagination:

<?php wp_pagenavi( array( 'query' => $news_query ) ); ?>                 

You can customize the output of your rows editing the following part inside your loop:

<tr>
    <td><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></td>
</tr>

with WordPress' Template Tags to add further information like the excerpt or thumbnail: http://codex.wordpress.org/Template_Tags#Post_tags .

share|improve this answer
    
yes it is a simple list of my posts but i am using tables instead of the default wordpress excerpts. just as in the link you provided me with when you select the image it links to the specific post in the table. all i want to do it limit the number of rows on my table to 20 rows per page. –  Blair Jun 30 '13 at 18:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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