This is probably a really simple question but how can I make the following view give me an offset of 1?
It is possible isn't it?

<?php
    $view = views_get_view('Featured_Venue_1');
    print views_build_view('block', $view, array(), false, 1);
?>

Comments

merlinofchaos’s picture

Status: Active » Fixed

You're almost there.

/**
 * This builds the basic view.
 * @param $type
 *    'page' -- Produce output as a page, sent through theme.
 *      The only real difference between this and block is that
 *      a page uses drupal_set_title to change the page title.
 *    'block' -- Produce output as a block, sent through theme.
 *    'embed' -- Use this if you want to embed a view onto another page,
 *      and don't want any block or page specific things to happen to it.
 *    'result' -- return an $info array. The array contains:
 *      query: The actual query ran.
 *      countquery: The count query that would be run if limiting was required.
 *      summary: True if an argument was missing and a summary was generated.
 *      level: What level the missing argument was at.
 *      result: Database object you can use db_fetch_object on.
 *    'items' -- return info array as above, except instead of result,
 *      items: An array of objects containing the results of the query.
 *    'queries' -- returns an array, summarizing the queries, but does not
 *      run them.
 * @param $view
 *   The actual view object. Use views_get_view() if you only have the name or
 *   vid.
 * @param $args
 *   args taken from the URL. Not relevant for many views. Can be null.
 * @param $use_pager
 *   If set, use a pager. Set this to the pager id you want it
 *   to use if you plan on using multiple pagers on a page. To go with the
 *   default setting, set to $view->use_pager. Note that the pager element
 *   id will be decremented in order to have the IDs start at 0.
 * @param $limit
 *   Required if $use_pager is set; if $limit is set and $use_pager is
 *   not, this will be the maximum number of records returned. This is ignored
 *   if using a view set to return a random result. To go with the default
 *   setting set to $view->nodes_per_page or $view->nodes_per_block. If
 *   $use_pager is set and this field is not, you'll get a SQL error. Don't
 *   do that!
 * @param $page
 *   $use_pager is false, and $limit is !0, $page tells it what page to start
 *   on, in case for some reason a particular section of view is needed,
 * @param $offset
 *   If $use_pager == false, skip the first $offset results. Does not work
 *   with pager.
 *   without paging on.
 * @param $filters
 *   An array of exposed filter ops and values to use with the exposed filter system
 *   Array has the form:
 *     [0] => array('op' => 'foo', 'value' => 'bar'),
 *     [1] => array('value' => 'zoo'), // for a locked operator, e.g.
 *   If no array is passed in, views will look in the $_GET array for potential filters
*/
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0, $filters = NULL) {

You just need to send in the $offset argument.

macm’s picture

Is is possible pass arguments to sort? (by date, by update, by name)

Regards

Mario

macm’s picture

Is is possible pass arguments to sort? (by date, by update, by name) ASC DESC

Regards

Mario

Anonymous’s picture

Status: Fixed » Closed (fixed)
jdevries’s picture

Status: Closed (fixed) » Active

Sorry to reopen it, but I'm running into this offset issue. I'm trying to get this piece of code to run properly:

  $view = views_get_view('frontpage');
  print views_build_view('embed', $view, $args, false, 9, false, 1);

They way I understand it it should skip my results by one and display only the the next nine. Unfortunately, the offset does not seem to stick. It will display nine results, but always starting with the first, instead of the second. What might I be doing wrong?

madwalo’s picture

ho can i g et t he values of views?
i don't mean build the view, i just want to get all the variables that view gives to me like view name, view tittle, view id etc....

muka’s picture

Try this


$view = views_get_view("my_view");

//var_dump($view);

$view_parts = views_build_view($type = "items", $view);
//var_dump($view_parts);

foreach($view_parts['items'] as $el){
  $node = node_load($el->nid);
  //var_dump($node);
}

lu

sun’s picture

Status: Active » Fixed

I think the question has been answered.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.