Monthly archive - Show only entries of the current blog?
Lausch - March 7, 2008 - 05:21
hi guys,
i try it since some hours now and i dont find a solution....
i tryd 100 different view args and it dont work. please someone help me...
i created a view to show a monthly archive on a user blog.
$view = new stdClass();
$view->name = 'monthly_archive';
$view->description = 'Monthly Archive';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Monthly Archive';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'blog/archive';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->block = TRUE;
$view->block_title = 'Archive';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = TRUE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'monthyear',
'argdefault' => '5',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
array (
'type' => 'uid',
'argdefault' => '5',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'blog',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;now my big problem.
i want to show a block with this view on every user blog. this works but it shows the archive of ALL blogs not only from the blog i viewing.
how can i do that?
i tryd the arg "userid is author" but im unable to set the argument to $node->nid
regards
Lausch

This will be great if
This will be great if someone knows how. I'm trying to achieve the same thing. Any help would be appreciated. In case you did figure it out Lausch, can you post your results?
Kind regards,
Marius
hi i think a possible
hi
i think a possible solution will be a short argument handling code. but i dont know much about this.
you can just create the agrument field "uid is author"
if you watch your blog you will just see something like
blog/archive/200803
if you copy and paste the link in your browser and add the uid, like user 1 or 2
blog/archive/2008031
blog/archive/2008032
it will only show result of user 1 or 2
so i dont know how to add the $node->uid
[ or for my system also arg(1) is possible coz my blog url are /blog/UID/NID ]
to the archive link
...
regards
Lausch
Yes Lausch that
Yes Lausch that worked...actually for me it would be this url structure:
blog/archive/200803/1
blog/archive/200803/2
it will only show result of user 1 or 2.
Could this help, using the views theme wizard it spit out some code which possible could be altered to manipualte the output? I'm not sure if this is helpful.
This code goes in your template.php file:
<?php
/**
* views template to output a view.
* This code was generated by the views theming wizard
* Date: March 15, 2008 - 7:36am
* View: MonthlyArchive
*
* This function goes in your template.php file
*/
function phptemplate_views_view_list_MonthlyArchive($view, $nodes, $type) {
$fields = _views_get_fields();
$taken = array();
// Set up the fields in nicely named chunks.
foreach ($view->field as $id => $field) {
$field_name = $field['field'];
if (isset($taken[$field_name])) {
$field_name = $field['queryname'];
}
$taken[$field_name] = true;
$field_names[$id] = $field_name;
}
// Set up some variables that won't change.
$base_vars = array(
'view' => $view,
'view_type' => $type,
);
foreach ($nodes as $i => $node) {
$vars = $base_vars;
$vars['node'] = $node;
$vars['count'] = $i;
$vars['stripe'] = $i % 2 ? 'even' : 'odd';
foreach ($view->field as $id => $field) {
$name = $field_names[$id];
$vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
if (isset($field['label'])) {
$vars[$name . '_label'] = $field['label'];
}
}
$items[] = _phptemplate_callback('views-list-MonthlyArchive', $vars);
}
if ($items) {
return theme('item_list', $items);
}
}
?>
Any thoughts?
Regards,
Marius
IT WORKS! UID / NODE->UID based Monthly Archive!
hi mariusooms,
look, i tryd very much and im unable to set an arg after arg(2) (200803 in blog/archive/200803)
so i moved the argument handling code to position 1 and added some arg code and changed the site title to blog/$arg/archive
now it works, i got it! :-)
i use blog/$user->uid on my site, if you use the same, you can use my export to get a working version for each user :-)
<?php
$view = new stdClass();
$view->name = 'monthly_archive';
$view->description = 'Monthly Archive';
$view->access = array (
0 => '1',
1 => '2',
);
$view->view_args_php = 'if (arg(0) == \'node\' && is_numeric(arg(1))) {
$node=node_load(arg(1));
$args[0] = $node->uid;
}
else {
$args[0] = arg(1);
}
return $args;';
$view->page = TRUE;
$view->page_title = 'Monthly Archive';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'list';
$view->url = 'blog/$arg/archive';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->block = TRUE;
$view->block_title = 'Archive';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = TRUE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'uid',
'argdefault' => '5',
'title' => '',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
array (
'type' => 'monthyear',
'argdefault' => '5',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'blog',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;
?>
explaintation of my arg code:
i saw, that arg(1) is blog/UID only if im on the blog homepage,
thats normally coz if im on a node arg(1) is NID (node/123)
so i added a code that checks whether you are on a node or not
if you on a node, i load the node and set my arg to $node->uid
the output is always something like this:
blog/1/archive/200803
blog/arg(1) or node->uid/...
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) { // check whether its a node or not
$node=node_load(arg(1)); // if its a node
$args[0] = $node->uid;
}
else {
// if no node, it have to be the blog homepage so UID is arg(1) (blog/UID)
// arg(1) is the UID of my blog coz my url alias blog/[UID]
// if you have another link that includes the UID, just change arg(1) to your UID arg
$args[0] = arg(1);
}
return $args;
?>
so, this crap really working.
only one LITTLE problem will be open
if you visit the archive the breadcrumb is a little buggy
Home › Weblogs › My Weblog › Monthly Archive › Monthly Archive
The first Monthly Archive is a wrong link...
but this is a little problem.
i will add a custum breadcrumb code with drupal_set_breadcrumb
i hope i could help you (and me) :-)
regards
Lausch
PS: now i have to find the same for tagadelic, than my multi user blog is perfect! :-)
Very nice Lausch, I will try
Very nice Lausch, I imported your view code and was actually able to keep my blog alias just fine. I use home/user/blog for blog path and just changed the views page archive path to home/$arg/blog/archive.
Now I have this for the blog:
/home/marius/blog
and the following for archives (where 5 is my uid):
/home/5/blog/archive
I would like for $arg to return the name rather than uid. It must be possible to set the $args to $user->name in the handling code. Have any ideas?
I have just downloaded Tagadelic and some related modules last night. I guess we are at about the same stage for multi-user blog. The Community Tags module is pretty cool. Now if I could have the 'uid' change to 'name' in the blog archive path, it will be perfect for me as well. I don't use breadcrumbs, so I'm okay there.
Thanks for thinking with me,
Marius
try this
hi, i dont think that community tags is my solution for the tagadelic problem.. but back to topic
ehm
hm if you dont use userid as arg(1) i see the only solution if you get the UID from Username directly from the db. i dont know another way...
its bad than we could no uid or anything from the blog homepage (ok maybe we could but i dont know how)
modify the argument handling code like this. i dont tested it so far...
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) { // check whether its a node or not
$node=node_load(arg(1)); // if its a node
$args[0] = $node->uid;
}
else {
// new code
$sql = "SELECT uid FROM {users} WHERE name = 'arg(1)'";
$result = db_query(db_rewrite_sql($sql));
$userid = db_fetch_object($result);
$userid = $userid->uid;
$args[0] = $userid;
}
return $args;
?>
regards
Lausch
PS: please give me updates if you found any solution or part solution for the tagcloud by user
Nope...that gave some weird
Nope...that gave some weird url results. I can live with uid showing rather than the username. I'm already so happy that the monthly archives are working correctly.
I will post my progress on user tagclouds, that will be the next point of interest.
Regards,
Marius
An easier solution
Hi,
I think an easier solution is to install the Pathauto and Token -modules and give all the blog entries a path of blog/[author-name-raw]
That way you can just reference the argument from the url.
hi, i think you dont
hi,
i think you dont understood this topic :-)
im wrong?
show me some examples!
regards
Lausch
I haven't tried it from
I haven't tried it from inside a block, but I have just created what schonae is describing, plus a view with args to run the archive:
Pathauto, for blog entries: blog/[author-name-raw]/[yyyy]/[mm]/[title-raw].html
Then a page view at /blog with 3 arguments:
User: Username is Author (default: Display All Values)
Node: Posted Year (default: Display All Values)
Node: Posted Month (default: Display All Values)
and a filter of Type=Blog Post, of course.
Now I have
1 post /blog/howie/2008/03/blog-post-1.html
1 month /blog/howie/2008/03/
1 year /blog/howie/2008/
all time /blog/howie/
all blogs, all time /blog/
with one view :-)
Isn't that what you were looking for?