• Resolved amfarr

    (@amfarr)


    I’m trying to display posts in a page template so my site has another blog page that displays only posts with a certain category. I found this code and it works fine to show all my posts in the same basic layout.

    I want to customize that code to use the mullet loop like my index.php and also only display a certain category.

    Here’s my modified mullet loop located in index.php:

    <?php if (have_posts()) : ?>
    		<?php $count = 0; ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<?php $count++; ?>
    			<?php if ($count == 1) : ?>
    			<div id="recentpost">
    				<div id="post-<?php the_ID() ?>" class="post">
    					<div id="postthmb">
    					<img src="<?php echo get_post_meta($post->ID, "Thumbnailbg", true);?>" />
    					</div>
    					<div id="posttext">
    						<h2 class="post-title2"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark"><?php the_title() ?></a></h2>
    						<div class="post-meta2"><?php the_time('F j, Y'); ?></div>
    						<div class="post-content2">
    							<?php the_excerpt('Click here to read more &raquo;'); ?>
    						</div>
    						<div id="readmorej2"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">READ MORE...</a></div>
    					</div>
    				</div>
    			</div>
    			<?php else : ?>
    				<div id="post-<?php the_ID() ?>" class="post">
    					<div id="postthmb">
    					<img src="<?php echo get_post_meta($post->ID, "Thumbnailbg", true);?>" />
    					</div>
    					<div id="posttext">
    						<h2 class="post-title"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark"><?php the_title() ?></a></h2>
    						<div class="post-meta"><?php the_time('F j, Y'); ?></div>
    						<div class="post-content">
    							<?php the_excerpt('Click here to read more &raquo;'); ?>
    						</div>
    						<div id="readmorej"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">READ MORE...</a></div>
    					</div>
    				</div>
    			<?php endif; ?>
    		<?php endwhile; ?>
    	<?php else : ?>
    		<p>Sorry, no posts matched your criteria.</p>
    	<?php endif; ?>

    Any help would be appreciated!

Viewing 9 replies - 1 through 9 (of 9 total)
  • vtxyzzy

    (@vtxyzzy)

    If you just need this code to display only a certain category, see this thread for a possible plugin solution.

    Thread Starter amfarr

    (@amfarr)

    What I need is for the following code to do the same thing as the code up there. I need to display blog posts on a page template with a certain category.

    <?php
    $showposts = 3; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
       $args=array(
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       );
    $my_query = new WP_Query($args);
    ?>
    	<?php if( $my_query->have_posts() ) : ?>
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
    		<div id="post-<?php the_ID() ?>" class="post">
    			<div id="postthmb">
    			<img src="<?php echo get_post_meta($post->ID, "Thumbnailbg", true);?>" />
    			</div>
    			<div id="posttext">
    				<h2 class="post-title"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark"><?php the_title() ?></a></h2>
    				<div class="post-meta"><?php the_time('F j, Y'); ?></div>
    				<div class="post-content">
    					<?php the_excerpt('Click here to read more &raquo;'); ?>
    				</div>
    				<div id="readmorej"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">READ MORE...</a></div>
    			</div>
    		</div>
    		<?php endwhile; ?>
    	<?php else : ?>
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    	<?php endif; ?>
    vtxyzzy

    (@vtxyzzy)

    You can get a copy of the merged code here in the pastebin.

    I have no way to test it, so you may need to tweak it a bit.

    Thread Starter amfarr

    (@amfarr)

    You’re awesome! Thanks!

    One more thing though…how come when I put the code in for the prev and next pages it doesn’t show up but when I put the appendage /page/2/ it shows up but only the newer page link shows up…also on the second page the same 3 posts that were on the first page show up. Do you know why it’s doing that?

    vtxyzzy

    (@vtxyzzy)

    You need to enable pagination like this:

    <?php
    $showposts = 3; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $paged = intval(get_query_var('paged'));
    $paged = ($paged) ? $paged : 1;
       $args=array(
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       'paged' => $paged,
       );
    $my_query = new WP_Query($args);

    Also, showposts should be changed to posts_per_page.

    Thread Starter amfarr

    (@amfarr)

    Man I have a lot to learn!

    One more thing…I promise! How do I make it show only one category?

    vtxyzzy

    (@vtxyzzy)

    Check out the query_posts parameters in the Codex here.

    Change the 14 below to the id of the desired category:

    $args=array(
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       'paged' => $paged,
       'cat' => 14,
       );
    Thread Starter amfarr

    (@amfarr)

    I definitely will check that out. Thanks again! I wish I could tip you..haha.

    vtxyzzy

    (@vtxyzzy)

    You are welcome! Keep learning! Now, pleae use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display posts in page using mullet loop’ is closed to new replies.