Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Excluding a post in Wordpress
Old 11-09-2010, 01:27 PM Excluding a post in Wordpress
edgray's Avatar
Super Moderator

Latest Blog Post:
Frantic
Posts: 4,264
Name: Sugarcane Gray
Location: Hell, Southern Spain
Trades: 0
Working on this site right now and we've got a little problem. It's a "magazine" template wordpress site. You can see here: marbellas.com

The problem is we have a category called "Marbellas Blog". This category is already displayed in it's own box above the normal blog flow.

When we make a post to this category, the post appears twice: once in the allocated box and once in the normal blog flow.

How can I exclude this category from the front page yet stop it disappearing from this box?

The blog's allocated box code is:

Code:
<?php
//here we are going to extract the last blog post from the category called "X"
//we will also get a thumbnail for the post in case there is one

if (is_home()) {

//define the category you want to get from the blog and how many posts
$CategoryID="226";
$TotalPosts="1";
    
$recent = new WP_Query();
$recent->query('cat="'.$CategoryID.'"&showposts="'.$TotalPosts.'"');
while($recent->have_posts()) : $recent->the_post();    

//get the permalink url for the lin to the post
$permalink = get_permalink($post->ID);

//define the header box first with the title and set up the divs for the display
    echo "<div class='box'>";
    echo "<h2 style='font-weight:bold; font-size:14px;'>Latest Marbellas Blog Post</h2>";
    echo "<div class='block'>";
    echo "<img src='http://www.marbellas.com/images/Ms_icon_blo000.jpg' />";
    echo "<blockquote>";
    
    //now get the thumbnail and post content
    if (has_post_thumbnail()) {

        // the current post has a thumbnail
        $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 120,120 ), false, '' );
        echo "<div id='post-with-thumb'>";
      //  echo "<img src='/wp-content/themes/massivenews/thumb.php?src=".$thumb[0]."&w=120&h=120&zc=1&q=90'/>";
        echo the_content_limit(480, "");
        echo "<p></p>";
        echo "<a href=".$permalink." >Read More About It Here</a>";
        echo "</div>";

    } else {        

        //or get the first image from the post
        $thumb = get_first_image();
        echo "<div id='post-with-thumb'>";
    //    echo  "<img src='/wp-content/themes/massivenews/thumb.php?src=".$thumb."&w=120&h=120&zc=1&q=90'/>";
        echo the_content_limit(480, "");
        echo "<p></p>";
        echo "<a href=".$permalink." >Read More About It Here</a>";
        echo "</div>";

    }    

    echo "</blockquote>";
    echo "</div>";
    echo "</div>";

endwhile;

}
And then the posts begin, this is where I need to exclude the blog post category from.

Code:
        <div class="block">
          <div class="article first_main_article">
            <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
              <?php the_title(); ?>
              </a></h1>
            <div class="meta"> <span class="time">
              <?php //the_time('F j, Y'); ?>
              </span> <span class="categories">
              <?php the_category(', ') ?>
              </span> <span class="discuss">
              <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>
              </span>
              <?php if (is_user_logged_in()) : ?>
              <span class="editlink">
              <?php edit_post_link('Edit This Post', '', ''); ?>
              </span>
              <?php endif; ?>
            </div>
            
                  <?php
	//######################################################################
	//here we will get the thunmbail for the post
	if (has_post_thumbnail()) {
		// the current post has a thumbnail
		$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 120,120 ), false, '' );
		echo "<div id='post-with-thumb'>";
		echo "<img src='/wp-content/themes/massivenews/thumb.php?src=".$thumb[0]."&w=120&h=120&zc=1&q=90'/>";
		echo the_content_limit(470, "");
		echo "</div>";
		
	} else {
			
		//get the first image from the post
		$thumb = get_first_image();
		echo "<div id='post-with-thumb'>";
		echo  "<img src='/wp-content/themes/massivenews/thumb.php?src=".$thumb."&w=120&h=120&zc=1&q=90'/>";
		echo the_content_limit(480, "");	
		echo "</div>";
		
		//echo $thumb;
	}	

	//######################################################################
	?>
__________________

Please login or register to view this content. Registration is FREE
- a project in video and sound.

Please login or register to view this content. Registration is FREE
"Absolute Rubbish, an insult to the blues." - NME.

Please login or register to view this content. Registration is FREE
- Come use our agency :)
edgray is offline
Reply With Quote
View Public Profile Visit edgray's homepage!
 
 
Register now for full access!
Old 11-09-2010, 02:23 PM Re: Excluding a post in Wordpress
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try using query_posts after the allocated box but before the 'normal blog flow'.

http://codex.wordpress.org/Function_...ce/query_posts

PHP Code:
query_posts( array( 'category__not_in' => array($CategoryID) ) ); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-09-2010 at 02:25 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-09-2010, 02:54 PM Re: Excluding a post in Wordpress
edgray's Avatar
Super Moderator

Latest Blog Post:
Frantic
Posts: 4,264
Name: Sugarcane Gray
Location: Hell, Southern Spain
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Try using query_posts after the allocated box but before the 'normal blog flow'.

http://codex.wordpress.org/Function_...ce/query_posts

PHP Code:
query_posts( array( 'category__not_in' => array($CategoryID) ) ); 
Thanks for that, I actually ended up using this:

PHP Code:
if (is_home()) if (in_category('marbellasblog')) continue; 
__________________

Please login or register to view this content. Registration is FREE
- a project in video and sound.

Please login or register to view this content. Registration is FREE
"Absolute Rubbish, an insult to the blues." - NME.

Please login or register to view this content. Registration is FREE
- Come use our agency :)
edgray is offline
Reply With Quote
View Public Profile Visit edgray's homepage!
 
Old 11-09-2010, 03:57 PM Re: Excluding a post in Wordpress
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I guess that works but seeing break (outside of a switch statement) or continue make me cringe
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-10-2010, 02:57 AM Re: Excluding a post in Wordpress
edgray's Avatar
Super Moderator

Latest Blog Post:
Frantic
Posts: 4,264
Name: Sugarcane Gray
Location: Hell, Southern Spain
Trades: 0
Quote:
Originally Posted by NullPointer View Post
I guess that works but seeing break (outside of a switch statement) or continue make me cringe
so is your method a better way? I'm a PHP novice so if there's a better way it's probably good that I know!
__________________

Please login or register to view this content. Registration is FREE
- a project in video and sound.

Please login or register to view this content. Registration is FREE
"Absolute Rubbish, an insult to the blues." - NME.

Please login or register to view this content. Registration is FREE
- Come use our agency :)
edgray is offline
Reply With Quote
View Public Profile Visit edgray's homepage!
 
Old 11-10-2010, 09:41 AM Re: Excluding a post in Wordpress
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by edgray View Post
so is your method a better way? I'm a PHP novice so if there's a better way it's probably good that I know!
Interrupting control flow using break or continue is something you should avoid. Clearly using it once won't hurt much, but if you get in the habit of doing it your code is going to become more difficult to manage.

The alternative would be to embed your code in an if block where the condition is:
PHP Code:
if(!is_home() && !in_category('marbellasblog'))
{
     
//code here

Edit:
I should point out that there are some people who would disagree with me regarding the use of break and continue. Personally, as well as having been conditioned not to use them, I think they represent a style of coding that as a field we are moving away from.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-10-2010 at 09:46 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-10-2010, 05:00 PM Re: Excluding a post in Wordpress
edgray's Avatar
Super Moderator

Latest Blog Post:
Frantic
Posts: 4,264
Name: Sugarcane Gray
Location: Hell, Southern Spain
Trades: 0
thanks that actually makes good sense.

it's been a long long while since I've done any serious programming, and I haven't started writing any of my own apps yet, I should really start getting into the habit of good coding now.
__________________

Please login or register to view this content. Registration is FREE
- a project in video and sound.

Please login or register to view this content. Registration is FREE
"Absolute Rubbish, an insult to the blues." - NME.

Please login or register to view this content. Registration is FREE
- Come use our agency :)
edgray is offline
Reply With Quote
View Public Profile Visit edgray's homepage!
 
Reply     « Reply to Excluding a post in Wordpress
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25323 seconds with 12 queries