• tvance929

    (@tvance929)


    So I’m trying to create a simple list of posts from a certain category and I wanted to put that function in my functions.php so I could just call the short code.

    I get the list I want however, I also get the full posts below the list… ? I dont want the posts.

    (Also wondering how to get these posts in reverse Chronological order)…

    Here is my function:

    function getVolArchives() {
    	query_posts('category_name=volunteerspotlights&showposts=12');
    		echo '<ul style="list-style: none;">';
    	while (have_posts()) : the_post();
    
    		echo '<li style="width: 50%; float: left;"><a href="'. get_permalink() . '"><div style="font-size: 14px; font-weight: bold;">' . get_the_title() . '</div><div class="archiveName">' . get_the_date('F') . '</div></a></li>';
    	endwhile;
    		echo '</ul>';
    }
    
    add_shortcode('getVolArchives', 'getVolArchives');
Viewing 2 replies - 1 through 2 (of 2 total)
  • mrwweb

    (@mrwweb)

    Tvance,

    That’s odd and I’m not quite sure what would cause that.

    Because you’re not modifying the main query of the page, it’s more appropriate to use WP_query for this type of function.

    I do wonder whether you could resolve the issue by using wp_reset_postdata?

    Finally, for the post order, just use ‘order=DESC’.

    Best,
    -Mark

    Michael

    (@alchymyth)

    don’t use 'echo'in shortcodes – use 'return'or concatenate all results into one string and return that string at the end.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to create a loop in Functions without showing posts.’ is closed to new replies.