Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Link of the Week
Link of the Week
Link of the Week
MetaModPro is great! I want to provide a link to a different article on our site every week. Does this mean that I have to create 52 regular modules and 52 MetaMod modules? What if I wanted to offer a link of the day? Is that 365 + 365?
07-Nov-09 22:12:44
Re: Link of the Week
Great question dandytink. There are 2 main ways to approach this. Take your pick...
1 - If you "echo" anything inside the PHP box in MetaMod, that content appears in a new module of its own. Therefore if you want to dynamically create the HTML for a link to an article, then you can do it inside the MetaMod and it will appear as a module. Therefore you don't need to create any other modules at all. This works really well if you are simply creating some simple HTML with a dynamic link inside.
See Include PHP code directly in MetaMod for details on how to do this, and Include HTML directly in MetaMod for a simpler syntax for including HTML into MetaMod.
2 - If you want to include a more complex module that you can't recreate yourself in PHP (as above), then you may be able to use the following technique.
MetaMod is able to dynamically control the input parameters of other modules. With MetaModPro, you can control ANY module on the page, even if it's not inside MetaMod. With standard MetaMod, you can only control the parameters of modules included directly inside the MetaMod.
So, if you have some sort of module where you have to set the article to be displayed as a parameter of the module itself, then you can get MetaMod to dynamically change it. (this may be hypothetical - I am imagining a module where you have to pick the article that it has to link to, when you set up the module).
In that case, in the MetaMod you could do the following:
$mod_to_include = 101;
$changes->mod($mod_to_include)->setParam("article_id",53);
return $mod_to_include;
This assumes that module 101 has a parameter called "article_id" which controls which article it's going to display. MetaMod can change this dynamically before the module is rendered.
OK, in both these scenarios you are still going to have to work out how to tell MetaMod which article you are going to be featuring. Have you decided on that yet? Is it going to be random (generated each day/week) or are you going to be setting up a schedule for it?
Let's assume you want to make a schedule to change it every week.
$week_number = date("W"); // ISO-8601 week number, starting from 0
$articles = array(44,204,3212,22,55,56,57,58,...... 52 of these altogether...);
$article_id = $articles[$week_number];
... then you use one of the techniques above to use $article_id to link to the article.
Hope that gets you started,
Cheers,
Stephen
Re: Link of the Week
Thanks for the great response. With method 1, I will need to create 52 MetaMod modules and method 2 does it all within 1 MetaMod module? Is this correct? Is there an actual code example that I could see and modify? I'm sorry for my noob questions; I am really out of my league here.
Thank You, Dan.
Re: Link of the Week
Both methods are designed to avoid having to create 52 or 365 modules!!!
The question for you is though, what sort of module did you have in mind for the one that displays the links to other articles on the site? Were you going to create something with the "Custom HTML" module, or was there some other module, either built-in Joomla or 3rd-party, that you were thinking of using?
Assuming you were going to create Custom HTML modules, then you could instead just use MetaMod to construct the HTML, and not even use it to "pull in" other modules.
To expand the previous code:
Code:
$week_number = date("W"); // ISO-8601 week number, starting from 0
$articles = array(44,204,3212,22,55,56,57,58,...... 52 of these altogether...);
$article_id = @$articles[$week_number];
if ($article_id != null) {
$url = "index.php?option=com_content&view=article&id=" . $article_id;
echo "<h3>Article of the week</h3>";
echo '<a href="' . $url . '">Read more...</a>';
}
Just to be clear, this recipe does not pull in any external modules - it just creates some basic output which gets formed into a module.
Hope that helps,
Stephen
Re: Link of the Week
I'm sorry for being so thick-skulled. What I want is a module that changes every week. It would looks something like this:
Link of the Week
Click here to visit this week's link.
When they clicked on the link ("here") they would be taken to an article, i.e., article 4. Each week the module would appear the same; the only thing that will change is the link's destination. We would not say anything about the specific content of the linked article in the module. I'm sorry but I don't know much anything about PHP. In the code you attached, where do I put the variables and where do I enter text like Link of the Week?
Thank You, Dan.
Re: Link of the Week
Sure:
$week_number = date("W"); // ISO-8601 week number, starting from 0
if ($week_number == 7) return 123;
if ($week_number == 42) return 125;
That's all there is to it!
- Index
- » MetaMod
- » MetaMod General Support
- » Link of the Week
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7658
- Newest User:
- carre82601
- Members Online:
- 0
- Guests Online:
- 102
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked