Fork me on GitHub

Making ihome category-dependant in News module  Bottom

  • Hi, I want ihome param dependant of category, making it 0 if news category is 10010. Modified pnadmin.php in News/pntemplates, News_admin_update function:

    Code

    // Update the story
        if (pnModAPIFunc('News', 'admin', 'update',
                        array('sid' => $story['sid'],
                              'title' => $story['title'],
                              'urltitle' => $story['urltitle'],
                              '__CATEGORIES__' => $story['__CATEGORIES__'],

                                            ......................................

                              'ihome' => isset($story['ihome']) ? $story['ihome'] : 0,
                  'ihome' =>  ( $story['__CATEGORIES__'] == 10010 ) ? 0 : $story['ihome'] ,

                                            ......................................


    But this is not working. I suppose $story['__CATEGORIES__'] should get the cat id, so I don't understand why this is not changing the ihome value.

    What am I missing? Is $story['__CATEGORIES__'] not an integer? Quite new to PHP, and still figuring out how internal things work in Zikula.

    Thanks in advance!

    DÃ¥n
  • Hi,

    before digging into the code, what is it you are trying to obtain? I take it that you want a certain category not to be displayed in the homepage news list? Is that correct? It's more convenient to state what you would like to obtain on a little higher level. There might be other ways, that you haven't thought of.

    It 's better not to hack into the news code, but solve it in the templates IMHO. In that way you will be upgrade compatible later on. To me, it seems like a bad idea to put this kind of hard coded category values (which can change if you delete it or change it to another category) in the code.

    Let me check the code to see how to solve...

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • You are right, espaan, I was trying to modify the code because I think it couldn't be done with the templates. I saw the hardcoding category issue, I didn't think about upgrading in the future...
    I will try to explain this better:

    I am creating a news website, where some journalists write news using scribite. I want the 5 latest news to be shown in a block in the main page, all categories but one. The easiest way is using the option of "not to show in front page" for all the news in that category, so I thought I could make ihome to get this default value when the new is categorized at writing time.

    So at first it looked quite easy just adding a line of code to make it work...
  • Hi danx!
    Try the stroiesext extension here, with it you can make it as you discribed (with it you can select the categorys to be - or not to be - shown in a block)...
    greetz

    --
    Newsletter Project


    Visit the german speaking community!
  • Thanks a lot, I will try it

    DÃ¥n
  • That is indeed a better idea icon_smile
    There is a multi category selector in the storiesext block, which might suit your needs already. But I'm not all together sure that it will be what you want. So check it and report back if needed icon_wink
    BTW the storiesext block is merged into News from News 2.4 onwards.

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • I upgraded the news module from 2.1 (or something like that) to 2.41
    What I was trying to do can be done just great using storiesext, selecting the categories to be shown in the block. Thanks a lot both of you, your help was very useful indeed.

    Still, I am very curious why the code I modified didn't work... Could you please tell me what was wrong? There are lots of things I can't see how are made in Zikula, like how the functions are called when a page is requested (in which order) and where are the variables initialized or declared. Taking a look at Zikula Cozi Wiki doesn't throw much light in it. Not is that I will start coding tomorrow a great new module, but at first I thought the Zikula structure was a lot simpler than it is ;)

    Thanks again

    DÃ¥n



    edited by: danx, Aug 19, 2009 - 12:58 PM
  • Hi, great that you got it working to your liking. Don't hesitate of course to ask questions if needed.

    The Zikula structure is not that hard once you get to know it icon_biggrin I write that down and realize that that is true for a lot of things.
    Within News the function News_user_create in pnuser.php and pnuserapi.php are the ones that are called when a new article is created. You can call it as a plain user or an admin in which case the permissions determine what you see in the template (news_user_new.htm or news_admin_new.htm)

    The categories object is not that easy to figure out. The categories object has a hierarchy for the category registry properties that exist. So you have for instance __CATEGORIES__.Main.id (Main is here the property under which the category is registred in the category registry).
    you can compare that with the category id you would want to filter out.

    You can add to the bottom of a template, like the news_user_view.htm and when logged in as admin you will get all the available variables as a popup. You should see the category object structure in there. (I haven't tested it in this template now, but in general that works perfectly).

    --
    campertoday.nl, Module development, Dutch Zikula Community

This list is based on users active over the last 60 minutes.