WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Older or previous posts link displays same posts on index page (4 posts)

  1. jamesb4551
    Member
    Posted 5 years ago #

    Dear wordpress guru's, my older posts link on my index page is not working, it keeps displaying the same posts even though the link displays /?paged=2 etc. I think I have found the code to fix it but am not sure where to put it because I'm using a custom theme. This is what I need I think http://wordpress.org/support/topic/57912?replies=9 vut can someone with PHP knowledge tell me where to impliment this code?

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-3&paged=$paged");
    }
    ?>

    into my code here ....

    <?php get_header(); ?>
    <?php
    $landingPage = array();
    $landingPage[0]->name = 'allnewposts';
    $landingPage[0]->posts = 8;
    ?>
    <div id="column1" style="width: 550px;">
    <div class="posts">
    <div class="post_top" style="background-image: url('<?php bloginfo('template_url'); ?>/images/block/<?php randomBackground("top"); ?>'); height:51px;">
    </div>
    <?php
    for ($i = 0; $i < count($landingPage); $i++) {
    $cat = $landingPage[$i]->name;
    query_posts('category_name=' . $landingPage[$i]->name . '&showposts=' . $landingPage[$i]->posts);
    if (have_posts()) : ?>

    <?php if ($i != 0) { ?>
    <div class="divider" style="margin-bottom:20px;"></div>
    <?php } ?>

  2. jamesb4551
    Member
    Posted 5 years ago #

    can't someone please help here! I need this asap it's killing me!

  3. jamesb4551
    Member
    Posted 5 years ago #

    I've tried searching pagination on the forums and alot of people have this same problem, I know it's due to my query_posts section, but I'm not sure on how to change it, basically I want 8 posts to show on the 1st page and therefore have made a category so that everytime a new post is made allnewposts is selected so that it can be displayed on the home page.

    Only problem is I really need the paginaiton to work or no one can easily navigate backwards. Can anyone see in the above code a way of dealing with why it won't work:
    I've tried the code:

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=allnewposts&paged=$paged");
    }
    ?>

    but this doesn't seem to do anything.
    Ideas please????

  4. jamesb4551
    Member
    Posted 5 years ago #

    --- BUMP----
    OK I've stripped back my index to minimum and tried everything mentioned in the forums but can't get the pagination to work on my index, can someone please look at my code and give me some advice. I believe it can be re-written to take out the query posts but I'm not sure how. I just want it to act like a normal blog and every post show on the first page.

    <?php get_header(); ?>

    <?php
    $landingPage = array();
    $landingPage[0]->name = 'allnewposts';
    $landingPage[0]->posts = 8;

    ?>

    <div id="column1" style="width: 550px;">

    <div class="posts">
    <div class="post_top" style="background-image: url('<?php bloginfo('template_url'); ?>/images/block/<?php randomBackground("top"); ?>'); height:51px;">
    </div>

    <?php
    for ($i = 0; $i < count($landingPage); $i++) {
    $cat = $landingPage[$i]->name;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=' . $landingPage[$i]->name . '&showposts=' . $landingPage[$i]->posts . '&paged=$paged');
    if (have_posts()) : ?>

    <?php if ($i != 0) { ?>
    <div class="divider" style="margin-bottom:20px;"></div>
    <?php } ?>

    <!-- CATEGORY HEADER START -->
    <?php

    // Convert the $cat variable to uppercase
    $page_heading_cat = strtoupper($cat);
    // Send a query to the database looking for [HEADING_category]
    $sql = "SELECT post_content FROM wp_posts WHERE post_title = '[HEADING_$page_heading_cat]' LIMIT 1";
    $result = @mysql_query($sql);

    // Get the page content
    $post_content = mysql_fetch_row($result);
    $post_content = $post_content[0];

    if ($post_content) {
    // Get the first image source
    $sub_start = @strpos($post_content, 'src="') + 5;
    $sub_end = @strpos($post_content, '"', $sub_start);

    // Use custom heading
    $heading_image = substr($post_content, $sub_start, $sub_end - strlen($post_content));
    }
    else {
    // Use default heading
    $heading_image = get_bloginfo('template_url') . "/images/block-headings/heading_$cat.png";
    }

    ?>
    <div class="post" style="margin-top:-20px; margin-bottom:-10px;">
    <img src="<?php echo $heading_image; ?>" alt="<?php echo $cat; ?>" />
    </div>
    <!-- CATEGORY HEADER END -->

    <?php $pointer = 0; ?>
    <?php while (have_posts()) : the_post(); ?>

    <div class="post" style="padding-top:0px; padding-bottom:30px;">

    <h2 id="post-<?php the_ID(); ?>" class="<?php echo $cat; ?>">" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <?php the_content('More...') ?>

    <div class="metadata">
    <div class="<?php echo $cat; ?>">
    <div class="alignright" style="text-align: right;">
    <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
    </div>
    <img src="<?php bloginfo('template_url'); ?>/images/comment.png" alt="" />
    <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>
    <?php if(function_exists('wp_email')) { email_link(); } ?>
    <?php edit_post_link('Edit this post', '
    ', ''); ?>
    </div>
    </div>
    </div>
    <?php $pointer++; if ($pointer < $landingPage[$i]->posts) { ?>
    <div class="divider"></div>
    <?php } ?>

    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Stuff') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Stuff »') ?></div>
    </div>

    <?php else : ?>
    <div class="post">
    <h2 class="center">No posts found</h2>
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    </div>
    <?php endif; ?>

    <?php } ?>
    <div id="bottom" style="background-image: url('<?php bloginfo('template_url'); ?>/images/block/<?php randomBackground("bottom"); ?>');"></div>
    </div>
    </div>

    <div id="column2" style="width: 270px;">
    <?php $cat = "girls"; include("sidebar.php"); ?>
    </div>

    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic