How do I incorporate, for example, trackerlite's latest posts into the front page of the front_page.module?

Comments

gabriella’s picture

I'am not shore that I understand what you mean here but..

You could use a php snippet like this, to generate a list of the X latest changes with a pager

<?php
$listlength="10";

$output = node_title_list(pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 1 ORDER BY n.changed DESC"), $listlength));
$output .= theme('pager', NULL, $listlength);
print $output;
?> 
helsinki’s picture

This is pretty close to what I want. :-)

Except I wouldn't mind it to be ordered by the latest added and not the latest changed. And also, can it be set to content type, ie. I want only nodes from flexinodes1-5 and not comments/blogs/forums?

___________________
http://www.wilba.org

gabriella’s picture

I think you could change ORDER BY to "n.created "and set WHERE to reflect the type you want...

...WHERE  n.type = 'flexinode-1' OR 'flexinode-2' AND n.status = 1 ORDER BY n.created DESC ...

If you want all flexinode types I think you could set WHERE to sometning like ... WHERE n.type LIKE 'flexinode%'
- if I remember correctly..

EDIT: I'm so sorry - I didn't remember that correct..

To get all type names starting with flexinode it should be WHERE n.type ='flexinode%'..

gabriella’s picture

You could use regexp and set WHERE to something like

.. WHERE n.type REGEXP 'flexinode-[1-5]' AND n.status = 1 ORDER ...
helsinki’s picture

Hi Gabriella

Thanks for posting back, including the extra edit. Unfortunately I can't get this to work. It's calling whatever the first flexinode is set to, but ignoring the second one. I've tried it with the flexinode% and with () and the OR statements, but none of them have worked.

When I used two flexinodes in the SQL with the OR, I switched the order and it returns always the first one. :-/

I checked and doublechecked things like spaces and apostrophes. No avail.

gabriella’s picture

Hm, I tried it on my site and it seems to work...
here is a piece of code that works for me, I only have 3 flexinode types so I chosed to call for all but nr 1 ...

<?php
$listlength="10";
$output = node_title_list(pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type REGEXP 'flexinode-[2-3]' AND n.status = 1 ORDER BY n.changed DESC"), $listlength));
$output .= theme('pager', NULL, $listlength);
print $output;
?> 
helsinki’s picture

You're a star...works a treat. Many thanks. The order in this thread is not so clever, so just to clarify, it was the REGEXP bit that sorted it out.

Maybe you should add it to the PHP snippets. It is a useful piece of code and there is nothing there yet that says how to pull node titles from multiple flexinode types.
__________________
http://www.wilba.org

jasonwhat’s picture

Great posts. I especially like the tip on posting multiple node types. I know most of this is in the php snippets portion of the handbook, but I figured this is a more active thread to ask a question. One problem I've had with snippets though is they don't seem to respect node access. For some sites I use Organic Groups to control access but when I use snippets all the content shows up regardless of access permissions for the node. Does some type of call need to be made to OG for the permissions?

Also, if I wanted any nodes with promoted status to show up (I think n.promote = 1) would I have to specify every node type in the snippet, or just not have the whole WHERE n.typ portion? Thanks.

helsinki’s picture

If I'm not mistaken, pulling the nodes from the node_title_list function means that it filters its results to comply with current permissions and access controls. Haven't needed to test it though.

gabriella’s picture

If you want any node type just take out the n.type

<?php
$listlength="10";
$output = node_title_list(pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.promote = 1 ORDER BY n.changed DESC"), $listlength));
$output .= theme('pager', NULL, $listlength);
print $output;
?> 

or if you just want certain node types, like stories and images,

<?php
$listlength="10";
$output = node_title_list(pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.promote = 1 AND (n.type = 'image' OR n.type = 'story') ORDER BY n.changed DESC"), $listlength));
$output .= theme('pager', NULL, $listlength);
print $output;
?> 
pamphile’s picture

.

sajithvk’s picture

If I use drupal/node page my front, it automatically shows snippets of last few posts which have promoted to front page option set. Can I get exactly the same facility in the frontpage module, with its additional flexibility? I think this feature was there in frontpage module previously (I am not sure about it, even though)

Phillip Mc’s picture

Hey Sajitchvk,

From the front_page.module readme.txt

PROMOTED TO FRONT PAGE Example snippet
----------------------------------------
The default front page when you install Drupal for the first time, is 'node' which displays a list of node teasers, where the nodes have been tagged as pages that are 'Promoted to Front Page'.

If you want to recreate that node listing after installing the front_page.module, simply paste the following snippet into the text area provided on the front_page settings page and select the PHP filter before saving your new configuration.

<?php
   print node_page_default();
?>

Phil

sajithvk’s picture

Thanks PhilK, I was looking for exactly this simple thing...