Forums

WP_Query Loop, pagination and tittle tag of a page (2 posts)

  1. evensgoddard
    Member
    Posted 7 months ago #

    Hello pleople, I'm not an expert but I try to do my best :) I'm trying to display 1 post in a page and paginate the rest of the posts using query_posts... everything works fine when I use the following code

    <div class="grid_8 alpha">
    <div class="content">
    	<?php
        if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page');
    	} else { $paged = 1;}
    	query_posts( array( 'category_name' => 'farandula','posts_per_page' => '1','post_type' => 'post', 'paged' => $paged ) );
    	global $more; $more = false;
    	if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post(); $count++;
        ?>
    	<div class="the-post-in-cat-wrapper">
    	<h2><?php the_title(); ?></h2>
    
    	<p class="date">Publicado el día: <?php the_time(get_option('date_format')); ?> por
    	<a href="<?php bloginfo('url')?>/author/<?php the_author_meta('nickname'); ?>/" title="Perfil de <?php the_author_meta('nickname'); ?>"><?php the_author_meta('nickname'); ?></a></p>
    	<?php the_post_thumbnail('medium', array('class' => 'alignleft')); ?>
    
    	<?php the_content('Continua leyendo este artículo...'); ?>
    	<?php edit_post_link('Editar esta página.', '<p>', '</p>'); ?>
    	</div>
    	<?php wp_pagenavi(); ?>
    	<div class="clear"></div>
    	<?php endwhile; endif;?>
    	</div>
    	</div>

    the problem is that I'm displaying this post in the home page and the title tag displays "Category name - Site Name" instead of "Site Name"

    When I use this other code here

    <?php
    	if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page');
        } else { $paged = 1;}
        $myQuery = new WP_Query( array( 'category_name' => 'farandula','posts_per_page' => '1','post_type' => 'post', 'paged' => $paged ));
    
        if ( have_posts() ) : $count = 0; while ( $myQuery->have_posts() ) : $myQuery->the_post(); $count++;
        ?>
        <div class="the-post-in-cat-wrapper">
        <h2><?php the_title(); ?></h2>
    
        <p class="date">Publicado el día: <?php the_time(get_option('date_format')); ?> por
        <a href="<?php bloginfo('url')?>/author/<?php the_author_meta('nickname'); ?>/" title="Perfil de <?php the_author_meta('nickname'); ?>"><?php the_author_meta('nickname'); ?></a></p>
    	<?php the_post_thumbnail('medium', array('class' => 'alignleft')); ?>
    
    	<?php global $more; $more = 0; the_content('Continua leyendo este artículo...'); ?>
        <?php edit_post_link('Editar esta página.', '<p>', '</p>'); ?>
        </div>
        <?php wp_pagenavi(); ?>
        <div class="clear"></div>
    	<?php endwhile; endif;?>

    It works and displays the title tag the way I want, the problem is that it's not displaying the Navigation bar, not even if I place <?php wp_pagenavi(); ?> outside of the loop.

    I've been reading a lot of articles but I'm unable to solve this one :(

    If anyone knows what's wrong, please help me :)

    Sorry for my English... it's been a while since the last time I wrote something in English. Thanks in advance :D

  2. evensgoddard
    Member
    Posted 7 months ago #

    This is why I love to use WordPress, there's always a super easy way to solve everything :D

    After a while I got it working just by adding wp_reset_query();
    So the final code looks like this:

    <?php
    	if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page');
        } else { $paged = 1;}
        $myQuery = new WP_Query( array( 'category_name' => 'farandula','posts_per_page' => '1','post_type' => 'post', 'paged' => $paged ));
    
        if ( have_posts() ) : $count = 0; while ( $myQuery->have_posts() ) : $myQuery->the_post(); $count++;
        ?>
        <div class="the-post-in-cat-wrapper">
        <h2><?php the_title(); ?></h2>
    
        <p class="date">Publicado el día: <?php the_time(get_option('date_format')); ?> por
        <a href="<?php bloginfo('url')?>/author/<?php the_author_meta('nickname'); ?>/" title="Perfil de <?php the_author_meta('nickname'); ?>"><?php the_author_meta('nickname'); ?></a></p>
    	<?php the_post_thumbnail('medium', array('class' => 'alignleft')); ?>
    
    	<?php global $more; $more = 0; the_content('Continua leyendo este artículo...'); ?>
        <?php edit_post_link('Editar esta página.', '<p>', '</p>'); ?>
        </div>
        <div class="clear"></div>
    	<?php endwhile; wp_pagenavi(); endif; wp_reset_query();?>

    It was an easy one but I didn't found anything pointing to that particular solution.

Reply

You must log in to post.

About this Topic