Skip to main content
deleted 59 characters in body
Source Link
Django Reinhardt
  • 1.7k
  • 5
  • 21
  • 38

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>
deleted 106 characters in body
Source Link
Django Reinhardt
  • 1.7k
  • 5
  • 21
  • 38

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

// Ignore stickied posts in main loop
query_posts(array("post__not_in" => $sticky_post_ids));

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

// Ignore stickied posts in main loop
query_posts(array("post__not_in" => $sticky_post_ids));

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>
added 103 characters in body
Source Link
Django Reinhardt
  • 1.7k
  • 5
  • 21
  • 38

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// BEGIN Custom "sticky" loop

// Get sticky post IDSposts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current catcategory only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

        endwhile; endif;
    // END Custom "sticky" loop

    // IMPORTANTReset post data ready for next loop
    wp_reset_postdata();
}

if (have_posts())// :
Ignore stickied posts in globalmain $i;loop
  query_posts(array("post__not_in" => $i$sticky_post_ids));

if =(have_posts()) 0;:

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);
        $i++;

    endwhile; endif; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

Like so:

<?php
// BEGIN Custom "sticky" loop

// Get sticky post IDS
$sticky_ids = get_option( 'sticky_posts' );

// If sticky posts found
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current cat only
        'post__in' => get_option('sticky_posts')
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

        endwhile; endif;
    // END Custom "sticky" loop

    // IMPORTANT
    wp_reset_postdata();
}

if (have_posts()) :
    global $i;
    $i = 0;

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);
        $i++;

    endwhile; ?>

The answer to both issues was pretty simple.

  1. Simply add an argument to WP_Query to limit to the current category
  2. Make sure that WP_Query doesn't run unless there's actually some sticky posts

It wasn't hard to ask WP to ignore stickied posts, too.

Like so:

<?php
// Get sticky posts
$sticky_ids = get_option( 'sticky_posts' );

// BEGIN Custom "sticky" loop

// If sticky posts found...
if(!empty($sticky_ids)) {
    $args = array(
        'post_type' => 'post',
        'category__in' => get_query_var('cat'), // Get current category only
        'post__in' => get_option('sticky_posts') // Get stickied posts
    );

    $sticky_posts = new WP_Query($args);

    if ($sticky_posts->have_posts()) :
        while ($sticky_posts->have_posts()) : $sticky_posts->the_post();

            get_template_part('post-formats/content', 'sticky');

    endwhile; endif;
// END Custom "sticky" loop

    // Reset post data ready for next loop
    wp_reset_postdata();
}

// Ignore stickied posts in main loop
query_posts(array("post__not_in" => $sticky_post_ids));

if (have_posts()) :

    /* Start the Loop */
    while (have_posts()) : the_post();

        $format = get_post_format();
        if (false === $format) {
            $format = 'standard';
        }
        get_template_part('post-formats/content', $format);

    endwhile; endif; ?>
deleted 372 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
Loading
Source Link
Django Reinhardt
  • 1.7k
  • 5
  • 21
  • 38
Loading