Forums

[resolved] Hide the first post in my blog (24 posts)

  1. Shaooxz
    Member
    Posted 1 year ago #

    I want that always the latest post of my blog will be hidden. I don't want to use a plugin for it, I want it to still be public but i don't want it to be show on the main page
    Thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Try something like:

    <?php $c = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    if( $c ==1 ) continue;?>

    in your theme's index,.php template file.

  3. Shaooxz
    Member
    Posted 1 year ago #

    Thanks!

  4. thisisedie
    Member
    Posted 1 year ago #

    Works great for me. I'm betting you just added it to the index.php instead of replacing <?php if (have_posts()) : while (have_posts()) : the_post(); ?> with esmis code.

  5. Shaooxz
    Member
    Posted 1 year ago #

    I had another problem in the code but now it works but i got another problem. It's hiding the first post in every page in my blog, i want it to hide just the first most updated post.

  6. MAS
    Member
    Posted 1 year ago #

    @shasoosh

    $paged = get_query_var('paged') ? get_query_var('paged') : 1
    query_posts('offset=1&paged=$paged');

    before this line if (have_posts()) : while (have_posts()) : the_post();

  7. Shaooxz
    Member
    Posted 1 year ago #

    Parse error: syntax error, unexpected T_STRING ?

    <?php $c = 0;
    $paged = query_get_var('paged') ? query_get_var('paged') : 1
    query_posts('offset=1&paged=$paged');
    if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    if( $c ==1 ) continue;?>
  8. MAS
    Member
    Posted 1 year ago #

    <?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    query_posts('offset=1&paged=' . $paged);
    if (have_posts()) : while (have_posts()) : the_post();
    ?>

    Try this;

  9. Shaooxz
    Member
    Posted 1 year ago #

    ^
    That shows me posts 2,3,4,5 in the first page but in page number 2 i also see posts number 2,3,4,5 :| instead of 6,7,8,9

  10. MAS
    Member
    Posted 1 year ago #

    global $query_string;
    query_posts($query_string . 'offset=1&posts_per_page=5&paged=' . $paged);

    instead of query_posts('offset=1&paged=' . $paged);

    OR

    <?php $c = 0;
    $paged = get_query_var('paged');
    if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    if( $c ==1 && $paged <=1) continue;?>
  11. Shaooxz
    Member
    Posted 1 year ago #

    I've configured word press to show me 5 posts at the main page (because i'm hiding the first) and after changing the code to your last offer i do get only posts 2,3,4,5 in the main page but in page number 2 i see 6,7,8,9,10 where i want to continue to see just 4 posts. Any idea?

  12. vtxyzzy
    Member
    Posted 1 year ago #

    Give this a try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts_per_page = 4;
    $offset = $posts_per_page * ($paged - 1) + 1;
    $args = array(
      'posts_per_page' => $posts_per_page,
      'paged' => $paged,
      'offset' => $offset,
    );
    query_posts($args);
  13. Shaooxz
    Member
    Posted 1 year ago #

    Parse error: syntax error, unexpected T_ENDWHILE

  14. vtxyzzy
    Member
    Posted 1 year ago #

    I copied that straight out of a working test file, so the error is not in the code I posted. Perhaps it is not in the correct place in your code. Post some of your with a few lines before and a few lines after the added code.

  15. thisisedie
    Member
    Posted 1 year ago #

    shasoosh, this works for me. I suspect, as vtxyzzy said, that you aren't putting it in the right place. Out of curiosity, why do you want to hide the first post on each page?

  16. Shaooxz
    Member
    Posted 1 year ago #

    few lines from my index.php:

    <?php if ((!function_exists("check_theme_footer") || !function_exists("check_theme_header"))) { ?><?php { /* nothing */ } ?><?php } else { ?>
    
    <?php get_header(); ?>
    
    <?php include (TEMPLATEPATH . '/sidebar-left.php'); ?>
    
    <div id="content">
    
    <div id="content-inner">
    
    <?php $featured_slider_activate = get_option('rk_ecobox_featured_slider_activate'); if(($featured_slider_activate == '') || ($featured_slider_activate == 'No')) { ?>
    <?php { /* nothing */ } ?>
    <?php } else { ?>
    <?php if(is_home()) { ?>
    <?php include (TEMPLATEPATH . '/featured.php'); ?>
    <?php } ?>
    <?php } ?>
    
    <div id="post-entry">
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts_per_page = 4;
    $offset = $posts_per_page * ($paged - 1) + 1;
    $args = array(
      'posts_per_page' => $posts_per_page,
      'paged' => $paged,
      'offset' => $offset,
    );
    query_posts($args);
     ?>
    
    <div class="post-meta" id="post-<?php the_ID(); ?>">
    
    <div class="image">
        <h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    </div>

    I don't want to hide the first post on each page.... i'll try to explain my self better. In my homepage and on every main page i got a summary of my 4 latest posts. Above that i got a slideshow of posts of my choosing. When i post something new i'm putting it in the slideshow and doesn't want it to be shown again in the summary. (the slide show is on every main page) so what i want to accomplish is:
    First post will be hidden from the summary but will still be public,
    main page: 2,3,4,5
    2 page: 6,7,8,9
    3 page: 10,11,12,13

  17. vtxyzzy
    Member
    Posted 1 year ago #

    shasoosh, that is exactly what the code I posted will do: skip the first post on the first page and then show 4 posts per page without skipping any more.

    Unfortunately, you did not show enough code after the query_posts to be able to help find the problem. Maybe you should post the whole index.php in the pastebin and post the link here.

    Since I can't see more code, this is a guess. You may be missing the while test after the query. Try using this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts_per_page = 4;
    $offset = $posts_per_page * ($paged - 1) + 1;
    $args = array(
      'posts_per_page' => $posts_per_page,
      'paged' => $paged,
      'offset' => $offset,
    );
    query_posts($args);
    if (have_posts()) {  // You may need a colon here istead of a {
       while (have_posts()) {   // Same here
     ?>
    
    <div class="post-meta" id="post-<?php the_ID(); ?>">
    
    <div class="image">
        <h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    </div>
  18. Shaooxz
    Member
    Posted 1 year ago #

    Nop, still getting an error.
    Here is my original index.php without any changes made from this thread
    http://dl.dropbox.com/u/17838/index.php

    Thanks guys :)

  19. vtxyzzy
    Member
    Posted 1 year ago #

    OK - change this:

    <div id="post-entry">
    
    <?php $postcounter = 1; if (have_posts()) : ?>
    <?php while (have_posts()) : $postcounter = $postcounter + 1; the_post(); $do_not_duplicate = $post->ID; $the_post_ids = get_the_ID(); ?> 
    
    <div class="post-meta" id="post-<?php the_ID(); ?>">

    to this:

    <div id="post-entry">
    
    <?php $postcounter = 1;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts_per_page = 4;
    $offset = $posts_per_page * ($paged - 1) + 1;
    $args = array(
      'posts_per_page' => $posts_per_page,
      'paged' => $paged,
      'offset' => $offset,
    );
    query_posts($args);
    if (have_posts()) : ?>
    <?php while (have_posts()) : $postcounter = $postcounter + 1; the_post(); $do_not_duplicate = $post->ID; $the_post_ids = get_the_ID(); ?> 
    
    <div class="post-meta" id="post-<?php the_ID(); ?>">
  20. Shaooxz
    Member
    Posted 1 year ago #

    Works like a charm! Thanks all!!!! :)

  21. vtxyzzy
    Member
    Posted 1 year ago #

    You are welcome!

  22. muratje
    Member
    Posted 1 year ago #

    vtxyzzy

    I love you :D

  23. AnsonA4
    Member
    Posted 1 year ago #

    This worked great for me except that after page 6, the "older posts" button is no longer an option. If I go to ansonalex.com/page/7 the proper page displays however the navigation has disappeared. Here is my code (mine is a little different, I have 3 posts that I do not want displayed and I want to display 10 posts per page):

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 3;
    $posts_per_page = 10;
    $offset = $posts_per_page * ($paged - 3) + 3;
    $args = array(
      'posts_per_page' => $posts_per_page,
      'paged' => $paged,
      'offset' => $offset,
    );
    query_posts($args);
    
                if (have_posts ()) {
    
                    while (have_posts ()) {
    
                        (the_post());
  24. AnsonA4
    Member
    Posted 1 year ago #

    Update: There is also a "newer entries" link now on my index page, AnsonAlex.com, even though there aren't any newer entries.

    If you click it, it takes you to the same place you go to when you click "older entries".

    Other than those two above issues this fix works but if someone could shed some more light on the topic I would really appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.