Skip to content
WJunction - Webmaster Forum

Difference between these two lines of code for Wordpress

Status
Not open for further replies.
Code:
 <?php $wp_query = new WP_Query( '[COLOR=Red]category_name=&posts_per_page='.get_option('posts_per_page')[/COLOR]);
                 while ( $wp_query->have_posts() ) :  $wp_query->the_post();
                 
                 foreach((get_the_category()) as $category) {
                    $catname = $category->parent;
                    $cat_name = $category->name;
                    //$cat_parent= get_the_category_by_id( $catname);
                      $cat_id = $category->cat_ID;
                    if ($catname!=0)break;
                }
                
                //echo $catname . ' - ' . $cat_name;
                if(empty($catname)) $catname=$cat_id;
                 ?>
That is the original code, I replaced (1)
Code:
category_name=&posts_per_page='.get_option('posts_per_page')
with (2)
Code:
cat=-7&paged=' . $paged
Now Wp-pagenavi works, but what are the consequences of that? What does (1) do, vs (2) ?

Thanks in advance.
 
Last edited:

2 comments

PHP:
category_name=&posts_per_page='.get_option('posts_per_page')
category_name is empty so that means it will grab from all categories
posts_per_page = shows number of posts to show in each page

While
PHP:
cat=-7&paged=' . $paged
cat = categories seperated by id's to grab news of. Since you are using "-", it will show all other posts except from that category (7)
paged = display the posts that would appear on x page!
 
Status
Not open for further replies.

About the author

L
Active Member · Joined
402
Messages
39
Reactions
28
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom