List Blog Post by Site-wide Categories in index

Hi to everyone!

I am a new Elgg's user and I have some problems changing Index page.

My Elgg version is 1.8.8 and I need to show latest blopost's list in one of Index's boxes, but only from a specific category setted by Site-wide Categories plugin.

Example: Categories=News and Recipes(for cooking)

In my index I have:

box1[last blog_post] box2[last blog_post_news] box3[last blog_post_Recipes]

How can to do this? What subtype I must to use in this code?


"
$list_params = array(
'type' => 'object',
'limit' => 5,
'full_view' => false,
'view_type_toggle' => false,
'pagination' => false,
);

//grab the latest 5 blog posts
$list_params['subtype'] = 'blog';
$blogs = elgg_list_entities($list_params);

// lay out the content
$params = array(
'blogs' => $blogs,
'bookmarks' => $bookmarks,
'files' => $files,
'groups' => $groups,
'login' => $login,
'members' => $newest_members,
);
$body = elgg_view_layout('custom_index', $params);

// no RSS feed with a "widget" front page
global $autofeed;
$autofeed = FALSE;

echo elgg_view_page('', $body);
"
(code paste from custom_index plugin in file index.php)

 

 

 

 

  • Please don't make duplicate posts, it makes it harder for people to follow the conversation and wastes time/effort for people trying to answer your question.  I've deleted your other post.

  • @matt beckett

    thank's, i do not what is the best group for this issue and i post in both groups. Sorry for the error.  

  • Not sure if this will work. Try it with adding the following to custom_index/views/default/page/layouts/custom_index.php (you need to add it where it fits best for your needs and you also need to add the language strings used to your language file):

    $my_list_params = array(
        'type' => 'object',
        'subtype' => 'blog',
        'metadata_name' => 'universal_categories',
        'limit' => 4,
    );

    // news category
    $list_params['metadata_value'] = 'news';
    $latest_news = elgg_list_entities_from_metadata($my_list_params);

    // recipes category
    $list_params['metadata_value'] = 'recipes';
    $latest_recipes = elgg_list_entities_from_metadata($my_list_params);


    // output
    if (elgg_is_active_plugin('blog')) {
        echo elgg_view_module('featured',  elgg_echo("custom:news"), $latest_news, $mod_params);

        echo elgg_view_module('featured',  elgg_echo("custom:recipes"), $latest_recipes, $mod_params);
    }

  • @iionly

     

    Thank you for your help.
    Unfortunately, the code does just what I require.
    Practically in the box now shows only posts with a category set but does not distinguish between news and recipe. It also shows the whole post instead of just the extract.

    Do you have other suggestions?

     

    @

    fixed:

    I forgot to add the lines ...

    'full_view' => false,
    'view_type_toggle' => false,
    'pagination' => false,

    in $ my_list_params

    and add $ my_ in $ list_params ['metadata_value'] = 'News', to filter the category name.

    Thank you very much for your help.

    [for correctness insert the code  fixed]

     

    $my_list_params = array(
        'type' => 'object',
        'subtype' => 'blog',
        'metadata_name' => 'universal_categories',
        'limit' => 4,

        'full_view' => false,

        'view_type_toggle' => false,
        'pagination' => false,
    );

    // news category
    $my_list_params['metadata_value'] = 'news';
    $latest_news = elgg_list_entities_from_metadata($my_list_params);

    // recipes category
    $my_list_params['metadata_value'] = 'recipes';
    $latest_recipes = elgg_list_entities_from_metadata($my_list_params);


    // output
    if (elgg_is_active_plugin('blog')) {
        echo elgg_view_module('featured',  elgg_echo("custom:news"), $latest_news, $mod_params);

        echo elgg_view_module('featured',  elgg_echo("custom:recipes"), $latest_recipes, $mod_params);
    }

  • Okay. Glad you got it. I just wanted to post basically the same (including the hint about the wrong variable name in my previous post that you found on your own by now). :)

  • The best practice is to put the plugin enabled check ( elgg_is_active_plugin('blog') ) on the very top, so that you can skip the DB search if the plugin is inactive.

  • I'm here again for a similar problem.

    Now I can not be the only show in the box group_blog_post Index.

    Where can I find the list of types and subtypes?

    I tried to write
    type => group
    subtype => blog

    but of course is wrong.
    How do I find the entity type of an object?

     


    P.S.
    I also thank @ Team Webgalli for the suggestion that surely will use

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking