Jump to content
Sign in to follow this  
Chris M

How can I add a custom loop to the "Feature Page" template?

Recommended Posts

Chris M

Hello, I am trying to get this loop to appear on a page where I am using the "Feature Page" template. I want it to appear somewhere under the id #pagelines_content. What would be the best (cleanest, safest) way to accomplish this? (And if there is something wrong with this loop code, please do feel free to suggest corrections/improvements). <?php query_posts('showposts=7&category_name=news'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php endif; ?>

Share this post


Link to post
Share on other sites
Jenny
These are the hooks you can use for features: [code]pagelines_before_feature pagelines_inside_top_feature pagelines_inside_bottom_feautre pagelines_after_feature pagelines_feature_before pagelines_fcontent_before pagelines_feature_text_top pagelines_feature_text_bottom pagelines_fcontent_after pagelines_feature_media_top pagelines_feature_after pagelines_feature_nav_before[/code]

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Jenny
You may also find this useful: [code]function my_recent_posts_shortcode($atts){ extract(shortcode_atts(array('limit' => 5, 'cat' => ''), $atts)); $q = new WP_Query('cat=' . $cat . '&posts_per_page=' . $limit); $list = ''; while($q->have_posts()) : $q->the_post(); $list .= sprintf( '%2$s
', get_permalink(), get_the_title() ); endwhile; wp_reset_query(); return $list; } add_shortcode('recent-posts', 'my_recent_posts_shortcode');[/code] Usage: [recent-posts] returns 5 posts from default cat [recent-posts cat="26"] return 5 from category 26 [recent-posts limit="3" cat="26"] returns 3 posts from category 26

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Chris M
Thanks Jenny! I found this second one to be VERY useful! A few questions though: 1.) How do you get code to appear in yellow blocks on this site? :-) 2.) How can I increase the limit from 5 to 7 posts? I did this, but it didn't increase it: extract(shortcode_atts(array('limit' => 7, 'cat' => ''), $atts));

Share this post


Link to post
Share on other sites
Chris M
Haha, whops... Nevermind on #2! I only had 5 posts in that category! I made a couple more mock posts, and now 7 are displaying...

Share this post


Link to post
Share on other sites
Jenny
Great! 1) To get code to appear in yellow blocks, just enclose it in [ code ] [ /code ] tags (remove the spaces). 2) Try leaving the code in the function as is (i.e. put it back to 5) but use the last shortcode listed above and change it to 7. (I'm not 100% sure on this but that's how it should work.)

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Chris M
Ok, here is question #3 (now that #2 is solved): 3.) How can I display the DATE of the post as well? I would like the DATE to appear first, then the title/permalink (as a link, which is already taken care of).

Share this post


Link to post
Share on other sites
Jenny
For the date, you should be able to include a PHP call where you want it to appear. View this handy little Wordpress page for more info: http://codex.wordpress.org/Function_Reference/get_the_date.

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Chris M
Thanks again Jenny! Will look into it... This solves my issue! Just need to tweak a few things now...

Share this post


Link to post
Share on other sites
Jenny
Glad to hear it! And if you need future help, feel free to start another topic. :)

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Chris M
Ok, having a little trouble with the date... Here is the code and format I am working with: [code]get_the_date(F jS, Y)[/code] Problem is, where, and how (echo?), to put it within the functions.php code you shared above. I would like my final outcome to appear like this: October 9th, 2011 ??” Linked Permalink Here

Share this post


Link to post
Share on other sites
Jenny
I've asked @pross to see if he can chime in and lend a hand. He knows how well I break PHP when I try to help. :)

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Chris M
Thank you once again... Hoping that someone will jump in here. I know that it has to fit in somewhere in/around/before this line: [code]$list .= sprintf( '%2$s
', get_permalink(), get_the_title() );[/code] Just not sure how...

Share this post


Link to post
Share on other sites
Simon
[code] $list .= sprintf( '%3$s -- %2$s
', get_permalink(), get_the_title(), the_date('F jS, Y', '', '', FALSE) ); [/code] try that

Share this post


Link to post
Share on other sites
Chris M
Thanks @pross ... That does indeed work, but there are a few issues: 1.) It only displays the date once, if posts are on the same date. 2.) I am trying to get all of it to be displayed in a list
  • and it is causing the entire list item to be underlined, not just the link , and I am not sure why. Here is the code: [code] $list .= sprintf( '
  • %3$s ??” %2$s
  • ', get_permalink(), get_the_title(), the_date('F jS, Y', '', '', FALSE) ); [/code]

    Share this post


    Link to post
    Share on other sites
    Simon
    Do you have a live example?

    Share this post


    Link to post
    Share on other sites
    Chris M
    @pross: I will private message you the live example. Thanks for your help!

    Share this post


    Link to post
    Share on other sites
    Chris M
    Figured out why the
  • was underlined!!! I had a text-decoration: underline; rule in my CSS! Totally missed that. But I still need the DATE to appear on each line, not just one time for a range of posts. Right now, it is showing the date only once, if there is more than one post on that date. I would like it to show the date on every line, regardless if there is more than one post on that date.

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this  

    ×