简体   繁体   中英

pager problem with drupal and taxonomy

Ok, so this is probably a silly question, but i thought i'd put it out there anyway:
I know it's a strange solution to a simple problem, but i needed to control the listing of the nodes in the taxonomy pages, which i didn't feel i got the traditional way. So i went ahead and created a module that fetches the nodes based on taxonomy (taxonomy_select_nodes()), and i wanted a pager to go along with that.

Here's the code:
function theModule_recipeList(){ $path = drupal_get_path_alias($_GET['q']); $args = explode("/",$path); $themePath = drupal_get_path("theme", "theTheme");

 $term = taxonomy_get_term_by_name($args[1]); $tid = $term[0]->tid; $nodes = taxonomy_select_nodes(array($tid)); $output = "<div id='recipeListWrapper'>"; while($row = db_fetch_object($nodes)){ $node = node_load($row->nid); if($node->uid != 1){ $userClass="user"; } else{ $userClass="admin"; } $output .= " <div class='receptThumbnailWrapper'> <div class='wrapper'> <img src='".base_path().$themePath."/graphics/recept-default-small.png' /> <h3><a href='".base_path() . $node->path."'>".$node->title."</a></h3> <div class='recipeType $userClass'></div> </div> </div> "; } $output .= "</div>"; return $output; 

}

Now, the module works as i planned and all (even though it is a duct tape sort of solution, i know), and the pager prints and works. The problem is that the pager prints before anything else.

I suspect that it is because i call taxonomy_select_nodes before $output is returned, but i need it to get the nodes i want.

Please, any suggestions is greatly appreciated.

/Anders

As Nikit suggested, I would recommend using the views module to create your list. You can use an argument to select the appropriate taxonomy term from the path. That way you've got the functionality you want without the need to write and maintain code.

In keeping with the duct tape approach, you could use CSS to move the Pager below your content.

#div-that-holds-pager-and-content {
position: relative;
padding-bottom: 50px;
}

#div-that-holds-pager {
position: absolute;
bottom: 10px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM