… but I assume there’s no way to do this on a per-post basis, i.e. without modifying the template? (Because there will be some posts which I want to behave “normally”)
i use an if statement to segregate my link entries, which are in a link category, from my normal entries, which are not in my link category.
Any chance you could post an example of how you do this, precisely? I’ve just looked at your site, and it looks like you’re doing what I’m trying to do …
Thanks!
J.
you’ll need to move all of your link type entries to category with id no 1. it’s usually called general.
then add the following functions to your my-hacks.php file.
function the_ID_number() {
global $id;
return $id;
}
function the_cat_id_number($postid=''){
global $tablepost2cat, $wpdb;
$catidno = $wpdb->get_var("SELECT category_id FROM $tablepost2cat WHERE post_id = '$postid' ");
return $catidno;
}
then you’ll need to adapt “the loop” to your template:
<?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
<?php $postidno = the_ID_number(); $catsidno = the_cat_id_number($postidno); if ($catsidno == 1) { ?>
//code for link post
<?php } else { // prints posts without excluded cat ?>
//code for normal post
<?php } // closes printing entries with excluded cats ?>
<?php } } else { // end foreach, end if any posts ?>
Sorry, no posts matched your criteria.
<?php } ?>
Does anyone have this running on 1.2?
If there a template avaiable that shows this working for the default template? I’m a bit confused about the else clause. Wouldn’t it also display the entries in the links category?
well it depends. if you’re applying multiple categories to a link entry and you’re not storing your links in category 1, then the else portion would display the entries in the links category. if your links only have one category, the links category, then the entries in the links category wouldn’t be displayed by the else statement.
David,
You could simplify it even more by making use of the function in_category. 😉
Anonymous
Wouldn’t it also work to just use the excerpt category as the criteria?
If it’s not null/empty, then create outside link… otherwise, spit it out like normal. I *think* the code might look something like this…
if (the_excerpt_rss()){
do outside link stuff...
} else {
do the regular stuff...
--- regular code here ---
}
As long as you *only* used the excerpt section for outside link URLs, This would allow you to have the functionality in any category right?
– Kathy
For just that fact…then you cannot use the excerpt for anything else.
Anonymous
Ok I just worked up an alternative. I wanted to be able to have linkblog style posts, on a per category basis instead of putting them all into a general links category. Using 1.2RC and the custom meta fields:
– First I created a key named URL, and the value entered is a fully qualified website address (Including the http://)
– Second I created a key name LB, and I’m using this like a toggle switch. In other words, if an entry is supposed to be for the “linkblog”, I enter a value here of “Yes”
Then, in my index.php page, just under divclass=storycontent, I made these modifications…
<?php //testing
$link=get_post_custom_values('URL');
$LB=get_post_custom_values('LB');
if ($link[0]&&$LB[0]){ // if there's a link attached and LB is yes ?>
» "><?php the_title(); ?><?php remove_filter('the_content', 'wpautop');
the_content('Details...', '', ''); ?>
<?php }else{ // do regular stuff ?>
<b class="storytitle" id="post-<?php the_ID(); ?>">» " rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></b>
<div class="meta"><?php edit_post_link(); ?></div>
<?php
remove_filter('the_content', 'wpautop');
the_content('Details...', '', '');
the_meta();
?>
<?php }//end else ?>
Seems to be working well 🙂 Thoughts? Foresee any future problems from it?
– Kathy
With using in_category and something similar to Matt’s implementation I can put a “link” post into multiple categories as long as one of those categories is the category for link posts. It saves the time from having to enter custom meta fields each time.
Anonymous
Good points actually…
in_category gives me call to undefined function though. Which build was this included in and/or which file is it supposed to be in?
Oh…I think Matt just recently added it in the last few days.