I'm looking for a simple piece of code (or a module) that would make the "homepage" link redirect me to the latest node in a given taxonomy list (ie: the latest published comic for a comic strip). I want it to be dynamic (so I can use it in tandom with the scheduler module, and have the site post strips automatically). It should just goto the most recent (based on timestamp, and published status) node in a specific taxonomy list with 2 terms (I have two types of strips, memorial in the event of someone passing, and standard, so it needs to go to the most recent of the two of them).
Help?
I've tried the Views module, and it works great... minus the fact that I have a few node-dependent blocks, and when a node isn't onscreen (and it's just a "view" of the latest post) they won't display content (ie: service links, and fivestar). Hence, I need to be on a specific node page for these to work.
Comments
When you say "specific taxonomy list"
When you say "specific taxonomy list" do you vocabulary?
Sorry, yes. Two terms from
Sorry, yes. Two terms from the same vocab.
Are they the only terms in the vocabulary?
Are they the only terms in the vocabulary or are the a subset?
only two terms in this given
only two terms in this given vocabulary
Ok, try this
Here is a simple module called latest, it has two files (below). Create a folder under modules called 'latest', create the two file latest.module and lastest.info (in the 'latest' folder). Enable the module, optionally set the default vocabulary to use. To use, use the path ''latest' (uses the default vocabulary if one is defined), or 'latest/{vid}' where {vid} is a vocabulary id (number). You can make this your default home page under "Administer" -> "Site configuration" -> "Site Information" by setting 'Default front page:'
latest.info
latest.module
This works very well, and I
This works very well, and I think it's close. Two things:
Is there any way to fix it so that it actually fully forwards a user to the latest piece of content, not just displaying it as the homepage? While I love the simplicity of this, it's also what the Views module can already do :-(
Change the first function
It will change the sort order and do drupal_goto() which should handle point (2).
function latest_page($vid = 0) {
if ( $vid ) {
$vid = variable_get('latest_vocabulary', 0);
}
$sql = "SELECT n.nid FROM {node} n JOIN {term_node} tn USING(nid) JOIN {term_data} td USING(tid) WHERE td.vid = %d ORDER BY n.created DESC";
$nid = db_result(db_query_range($sql, $vid, 0, 1));
if ( ! $nid ) {
drupal_not_found();
return;
}
drupal_goto("node/$nid");
}
PERFECT!
That's it dude, awesome!! :-D
Can someone tell me how to
Can someone tell me how to add in a verifier to check to make sure it's the latest PUBLISHED node? It's trying to take me to an unpublished node :-(
Small change
In the sql change
WHERE td.vid = %dtoWHERE td.vid = %d AND n.status = 1Block Code
Now, one last question, is there any way to create a code to put into the following section:
"Show block on specific pages: Show if the following PHP code returns TRUE (PHP-mode, experts only)."
So that the block only appears on the "latest" strip page (ie: the homepage, via the "latest" module)?
Are you making that the homepage
Are you making that the homepage unde "Administer" -> "Site confiigure" -> "Site information", ?Default front page:"?
Is so you can configure the block to only show on the home page by setting "Show block on specific pages" to "Show on only the listed pages." and under "Pages" adding "" (without the quotes).
Not quite...
Sadly, since the module redirects to a specific node (the most recent in a taxonomy) it does not work. Hence why I was thinking a simple string of PHP to evaluate whether the user was looking at the latest node in that specific taxonomy list (and if so, display the block) would work instead.
Tried...
Tried setting the block to display only on "
<front>" or "latest/1" and neither works...Subcribing
Interesting.
Greetings,
Martijn
How can this be done in D6?
I tried this in D6 and got an error:
warning: Missing argument 1 for latest_menu() in latest.module on line 16.and all possible paths are returning "Page Not Found":
/latest
/latest/{vid}
admin/settings/latest