Jump to content
golok

Displaying posts categories separately on a single page

Recommended Posts

golok    1
golok

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
Danny    1,327
Danny

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...


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
golok    1
golok

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
Rob    547
Rob

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.


Former PageLines Moderator, Food Expert and Raconteur

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


  • Similar Content

    • Queue-it
      By Queue-it+
      Hi,
      Previous webmaster has made short codes assigned to certain categories. For example: [pl_section section="loops" id="003"]  displays all the Job posts for tech. 
      But where can I assign a short code for a certain category? I can't find where to add the loop ID for the category.
       
      Thank you
       
    • Queue-it
      By Queue-it+
      I've created a new post category "Success stories" with Custom Post type UI. (in order to have a different layout for a different post category - blog post one layout, success stories another layout).
      New category "success stories" are "detached" from all the other posts, so they have a different layout, but the problem is that all of the success stories are also having the same exact content.
      So whenever I edit content (e.g. change body text) on one of success story posts, it also changes the content (body text) for all other Success story category posts. 
       
      Question: Is there a way to retain this separate category with it's own layout, and have a different content for each individual post? I'm using Pagelins templates. 
       Thanks in advance.
    • Queue-it
      By Queue-it+
      Hi,
      Is is possible to have different layouts for different Post categories? We have Blog posts, News posts and Case studies that all are posts, but is it possible to differentiate their layouts?
      So far when I change a post layout it affects all Post type pages. Could it be done somehow with creating a separate template? 
      Examples below
      https://queue-it.com/news/
      https://queue-it.com/blog/
       
    • mzhafzah
      By mzhafzah
      Hello
      I am using DMS 2 theme and I want to create a 2 different links on my website; each link should take you to a different blog post category. Although the process is easy, yet I can not figure out how to give each category page a unique design of its own; Any change I make on any page is applied to the other (I'm aware of the universal elements like the header and footer and I a am not talking about these.)
      Since I am new to wordpress in general, I am not sure if my description is sufficient; apologies if it is not.
      TycoonJé
    • jammersam
      By jammersam+
      Hi there,
       
      Having difficulty editing something on a site I'm working on.  In previous Pagelines versions, clicking a post category allowed one to see all of the posts in that category.  In the postloop for DMS, it seems I can only show max ten.  I'd like for any category (except the main blog page, which should remain in magazine mode with 10 max) to show its maximum content - any explanation on how I can do that?
       
      Thanks very much.
×