Forums

Mini-loop (25 posts)

  1. deaftone
    Member
    Posted 11 months ago #

    I read up on the info provided by codex on how to setup a mini loop on a page outside of wordpress and that's working fine, but im having such a hard time. This is the code im using:

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"http://news.deaf-monkey.com/index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
    }?>
    </ol>

    But the problem im having is whenever i try to modify it i just end up messing it up, i was wondering if anyone could help me customize it in such a way that i can remove the way it uses a numbering system to display the posts. To make it easier i think the latest blog posts section at the bottom of http://www.dreamten.com is exactly how i want my mini-loop to look like, which shows the date, comments and even the small 1px margins separating each post.

  2. bekabug
    Member
    Posted 11 months ago #

    That looks way more complicated than it should be, I think. Can you show me where in the codex you found that?

  3. deaftone
    Member
    Posted 11 months ago #

  4. bekabug
    Member
    Posted 11 months ago #

    <ul class="recent">
    <?php $the_query = new WP_Query('showposts=5&orderby=post_date&order=desc');
    
    while ($the_query->have_posts()) : $the_query->the_post();
    
    $do_not_duplicate = $post->ID; ?>
    
    <li><a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title(); ?>"><?php echo strip_tags(get_the_title(), '<a>'); ?></a></li>
    
    <?php endwhile; ?>
    </ul>

    Does that look a little easier to swallow?

  5. bekabug
    Member
    Posted 11 months ago #

    the ordered list tag in your code you posted is what is numbering it. if you change that to an unordered list you'll get bullets instead of numbers...but that query looks way too complicated.

  6. deaftone
    Member
    Posted 11 months ago #

    I think i might have not made myself clear enough in my first post, im not having a problem with the code in it's normal state, everything working for me, it's just that im having trouble customizing it into something like what http://www.dreamten.com did in their latest blog posts section at the bottom of the frontpage, showing the comments made on the latest posts, the date of the posts and etc. etc. I just want to modify

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"http://news.deaf-monkey.com/index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
    }?>
    </ol>

    To suit my site's front page as it currently displays my latest posts in this way:

    "1. Post
    2. Post 2
    3. Post 3"

    Hope i didn't just confuse things hahah.

  7. deaftone
    Member
    Posted 11 months ago #

    Oh right, so just ul instead of ol! Simple enough, but what about the other customizations? Is just that impossible for a newbie?

  8. bekabug
    Member
    Posted 11 months ago #

    er ok nevermind man it would help if i could read. *outside* of wordpress... let me start all over

  9. deaftone
    Member
    Posted 11 months ago #

    Hahaha, it's all good man, im sorry if i seem a bit lost when it comes to this, really bad at coding, but fortunately this is the last thing i wanna do for my site! Hahah, as you can see from http://www.deaf-monkey.com, the mini-loop below the logo and menu looks horrible and the type they have in http://www.dreamten.com would definitely look alot better lol!

  10. bekabug
    Member
    Posted 11 months ago #

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code>,<code>comment_count</code>,<code>post_date</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"%s\">%s</a> Posted: %s Comments: %s</li>", get_permalink($np->ID),$np->post_title,$np->post_date,$np->comment_count);
    } ?>
    </ul>
  11. bekabug
    Member
    Posted 11 months ago #

    geeze...the forum is trashing the code... all code tags need to be backtics `

    let me know if that works out for you

  12. deaftone
    Member
    Posted 11 months ago #

    i used this:

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('/nfs/c03/h04/mnt/57867/domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code>,<code>comment_count</code>,<code>post_date</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"%s\">%s</a> Posted: %s Comments: %s</li>", get_permalink($np->ID),$np->post_title,$np->post_date,$np->comment_count);
    } ?>
    </ul>

    as you suggested and i ended up with blanks instead. just check http://www.deaf-monkey.com

  13. deaftone
    Member
    Posted 11 months ago #

    Ah, i added the url in the printf section instead of:

    printf ("<li><a href=\"%s\">%s</a> Posted: %s Comments: %s</li>", get_permalink($np->ID),$np->post_title,$np->post_date,$np->comment_count);
    } ?>

    as you suggested, i added and made it:

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('/nfs/c03/h04/mnt/57867/domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code>,<code>comment_count</code>,<code>post_date</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"http://news.deaf-monkey.com/index.php?p=%s\">%s</a> Posted: %s Comments: %s</li>", get_permalink($np->ID),$np->post_title,$np->post_date,$np->comment_count);
    } ?>
    </ul>

    BUT it still isn't showing any thing.

  14. bekabug
    Member
    Posted 11 months ago #

    ah! you're not using permalinks. can you turn those on and then try my code without you manually putting the URL in there.

  15. deaftone
    Member
    Posted 11 months ago #

    Might need a few minutes, not sure how to activate permalinks! lol!

  16. bekabug
    Member
    Posted 11 months ago #

    Settings > Permalinks

    I think...

  17. deaftone
    Member
    Posted 11 months ago #

    I think it's on now, here it is:

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('/nfs/c03/h04/mnt/57867/domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code>,<code>comment_count</code>,<code>post_date</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"%s\">%s</a> Posted: %s Comments: %s</li>", get_permalink($np->ID),$np->post_title,$np->post_date,$np->comment_count);
    } ?>
    </ul>

    It's showing nothing atm. http://www.deaf-monkey.com

  18. bekabug
    Member
    Posted 11 months ago #

    Ok I am sorry I am making you more confused. Put your permalinks back to Default because they worked at one time.

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>, <code>comment_count</code>, <code>post_date</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li>%s <a href=\"http://news.deaf-monkey.com/index.php?p=%s\">%s</a> %s</li>", $np->post_date,$np->ID,$np->post_title,$np->comment_count);
    }?>
    </ul>
  19. deaftone
    Member
    Posted 11 months ago #

    Alright, i just put permalinks back to default
    and i just used the code you posted, still shows nothing ); dammit

  20. bekabug
    Member
    Posted 11 months ago #

    interesting...can you put your original code in and see if it works again?

  21. deaftone
    Member
    Posted 11 months ago #

    Lol, i just put in the original code which worked earlier. Now it doesnt O_O

  22. bekabug
    Member
    Posted 11 months ago #

    You are taking the code tags out, right?

  23. deaftone
    Member
    Posted 11 months ago #

    LOL! I forgot to do that for the last 2 tries, but it's up now.

    I'm using the latest piece of code you gave me:

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('domains/news.deaf-monkey.com/html/wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ul id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>, <code>comment_count</code>, <code>post_date</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li>%s <a href=\"http://news.deaf-monkey.com/index.php?p=%s\">%s</a> %s</li>", $np->post_date,$np->ID,$np->post_title,$np->comment_count);
    }?>
    </ul>

    It looks alot better than earlier, now i guess it's the part where i need to customize it to look something like the mini loop that dreamten.com has. Just as i asked earlier, is this too difficult for a newbie or?

  24. bekabug
    Member
    Posted 11 months ago #

    Ok phew! I thought I was losing my mind

    Open a new thread and ask for help on formatting the date and i can help you after you get that fixed. I could figure the date thing out but I can't test it and going back and forth is wearing me out. Better to find someone who actually knows how to do it..

    Good luck

  25. deaftone
    Member
    Posted 11 months ago #

    Yeah, been a few hours now, hopefully someone gives some feedback to the other thread i made, the current mini loop is just horrid loll.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.