Archived

This topic is now archived and is closed to further replies.

  • 0

Displaying posts categories separately on a single page


Question

Posted · Report post

Displaying posts categories separately on a single page.

Hello,

On any "standard" WP template, one can easily display on a single page several blog posts categories, in separate blocs, using the following code and parameters:
 

<h3>Featured Category 1</h3>
<ul>
<?php $recent = new WP_Query("cat=1&showposts=3&offset=1"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

<h3>Featured Category 2</h3>
<ul>
<?php $recent = new WP_Query("cat=2&showposts=3&offset=1"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
 

How can this be achieved on PageLines' templates? How can I have on the same page — but in different "blocs" — my posts from Category 1 and those from Category 2?

Also — although only partially related — it seems that when a page is set as the "Posts page" in the "Reading" settings, the Blog template take precedence over any other template chosen in the "Edit Page". For example, if my page "Blog" uses "Template 1", where a QuickSlider is set to appear above the Content in the active sections, theQuickSlider is not displayed and instead appears the Callout section added to the Blog page template.
 

Share this post


Link to post
Share on other sites

3 answers to this question

Posted · Report post

Rob,

Thank you for your input. Since I wasn’t really sure if AnyLoop was what I was looking for, I wrote a very basic section (my first one!) which retrieves the latest post of a given category, using first a new WP_Query, and other posts of the same category, using $theposts->load_loop();.

http://www.tibetnc.org/blog/

I provide below my “amateur” code for the discussion, but I wouldn’t advise anyone to use it...:

class PageLinesPostLoopGolok extends PageLinesSection {

    /**
    * Section template.
    */
   function section_template() {
        //Included in theme root for easy editing.
        ?>
        <div class="tncblog">
        <h1 class="bigtitle">BLOG</h1>

        <div class="featuredbox">
        <?php $recent = new WP_Query("cat=14&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
            <div class="featuredtitle"><h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1></div>
            
            <h4>By <?php the_author_posts_link(); ?> | <?php the_time('j F Y') ?></h4>
            <div class="alignleft"><?php echo get_the_post_thumbnail( $id, array(150,150) /*echo get_the_post_thumbnail( null, 'small' );*/ ); ?></div>
                <?php /* the_content('Read more...'); */ ?>
                <?php the_excerpt(); ?>
                <p><a href="<?php the_permalink() ?>" rel="bookmark">Read more ></a></p>
 
        <?php endwhile; ?><br />

        </div>
        </div>
            
        <?php

           query_posts("cat=14&showposts=6&offset=1");
           //Included in theme root for easy editing.
           $theposts = new PageLinesPosts();
           $theposts->load_loop();

    }

}
 

Although it would have been nice to have meta settings (to choose the category and the number of post), I’ll probably simply hardcode it as I don’t need such flexibility at present.

My “only” problem is about formatting. I noticed that if I use $theposts->load_loop(); posts are automatically formatted on two columns, even though “Magazine Layout Mode” is selected in the “Blog And Posts” page options. It’s ok, as I managed to format posts the way I want, but how could the formatting be controlled?

Once again, thanks for your help.
 

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

Try this plugin:  http://wordpress.org/extend/plugins/special-recent-posts/ as it allows you to place code by shortcode, which means you can place it on any page, a post, a sidebar, etc.   In the shortcode, you can select a category, number of posts, and a number of other options.

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

For you to use that code, you can either use a hook or create your own section. However, I would recommend you have a look at AnyLoop in the PageLines store, as it may be what you're looking for.

 

http://www.pagelines.com/store/sections/anyloop/

Also, when you set a page as the Post Page, its considered a Special Page, therefore going to Wordpress Admin Dashboard > Pages > Select the Page you have set as your post page will not do anything. Now that the Page is set as the Post page and considered special you need to go to Wordpress Admin Dashboard > PageLines > Page Options > Blog, to customisation the layout, sections etc...

Share this post


Link to post
Share on other sites