0

I am trying to create a Joomla site that would be showing the article order numbers (not Article ID) inside each article. that way I can handle it like a book.

Each page will show the article order number at the corner - like a page. That way I will be able to have the site modeled by categories and pages will show with their page number (Article Order number) at the corner.

I want to give the user the ability to watch the pages like they are reading books by categories.

I would be happy to know - how can I add the article order number (for each category) inside the article itself.

I am sure that there is a PHP code that can do that. Thanks so much for your help and assist. Arye

Arye Guetta
  • 45
  • 1
  • 9

2 Answers2

1

You'll need to override the default article layout in your template.

If your template doesn't already have an article layout, you can copy the default layout from components/com_content/views/article/tmpl/default.php inside your template override templates\[YOURTEMPLATE]\html\com_content\article\default.php (replacing [YOURTEMPLATE] by your actual template name.

You can then display ordering where you require it within your template by using

<?php echo $this->item->ordering; ?>

You'll most likely want to either check for a certain condition (the article's category, perhaps) to determine whether you want to display the ordering.

Another option is to create an alternative layout instead of overriding the default one. You can rename default.php in your template to, let's say bookpage.php. You will then be able to pick the new layout as an alternative layout in your articles' options.

Eric Maziade
  • 306
  • 1
  • 4
  • Thanks Eric, that looks in the right direction. I am not really sure I do understand it thoroughly - I need to change my layout (or create an alternative one) and put the php code you gave me inside the layout. How can I see the number inside the article? thank You – Arye Guetta Nov 18 '15 at 19:48
  • I meant to be able to style and position it - can I create a class inside the php? and also How can I add 1 to the order to avoid seeing 0 as page number? and a quick quetion - How can I make sure that the article are ordered in my category? Thank You! – Arye Guetta Nov 18 '15 at 19:55
  • Regarding the zero I have found out how to do that: echo $this->item->ordering+1; That works. – Arye Guetta Nov 18 '15 at 20:00
  • From within the layout file, you use basic PHP + html as you wish - wrap it in a span or a div tag with a class, place it where you need it to be within the template. To order the articles in the category, use the category filter in the backend, sort by order and use drag & drop. – Eric Maziade Nov 22 '15 at 05:11
  • Thanks Eric. I have already tried that and after I made the change - I could NOT load the article at all. I might be using the wrapping wrong - I use: echo "
    "; echo $this->item->ordering+1; echo "
    ";
    – Arye Guetta Nov 22 '15 at 06:06
  • What do you mean by "could not load the article at all" ? Suggests an error in the PHP code (error logs could help you out there).
    item->ordering + 1); ?>
    – Eric Maziade Nov 22 '15 at 12:55
  • Thanks. I have this Error:
    Parse error: syntax error, unexpected '<' in D:\xserver\htdocs\pets\templates\tml_13\html\com_content\article\default.php on line 76
    - It looks like the DIV is not written the correct way.
    – Arye Guetta Nov 22 '15 at 13:28
  • I have found the right way to do it - maybe I could done that shorter but - this one works just for now. echo "
    "; echo ($this->item->ordering + 1); echo "
    "; there should be using echo and \"pagenum\". thank You Eric. :)
    – Arye Guetta Nov 22 '15 at 13:39
  • That is most likely because you are placing html within a php block. – Eric Maziade Nov 22 '15 at 14:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95862/discussion-between-arye-guetta-and-eric-maziade). – Arye Guetta Nov 22 '15 at 18:24
0

you can get article id by using

Request::getVar('id');

for more you can check the link Joomla plugin : how to get article title and article id

for jquery you can do like this. you can create a function and call on every page load it will sort all your content accordingly. you can assign other attributes also in foreach loop.

<div id="allArticles">
   <article id="3">Article 3</article>
   <article id="1">Article 1</article>
   <article id="2">Article 2</article>
</div>

$("#allArticles article").sort(function (a, b) {
   return parseInt(a.id) > parseInt(b.id);
}).each(function(){
   var elem = $(this);
   elem.remove();
   $(elem).appendTo("#allArticles");
});

more you can see the working example here http://jsfiddle.net/THMu3/

Community
  • 1
  • 1
  • Thanks. But I was interesting in something different. As I have mentioned in my post - I am looking for article ORDER number - not the Id. I want to put the number inside the article (The ID will not help me at all since I will not be able to start from 1,2,3 etc...) I want to be able to put Joomla article order number inside the article itself. Since I add articles dynamically and sometimes the new articales push existing pages I can not do that manually - I need that to be added using a code. thanks – Arye Guetta Nov 15 '15 at 08:17
  • then i will suggest you to use Jquery. it will sort your articles accordingly and even for new coming articles. starting from 1,2,3 etc – Waqas Shakeel Nov 15 '15 at 08:27
  • Thanks. Can you please assist me with the JQuery that I need to use? – Arye Guetta Nov 15 '15 at 09:10
  • Thanks. Not sure that i am following your answer. I'm looking to be able to have all articles ordered in one category,ascending. I have (i.e.) 300 Articles that are already there using ID# 91,100,320,430 etc. Not 1,2,3. they have been created during a long period of time and the don't have following ID. The solution that i am looking for is - Being able to put the #1 in article id #91 and #2 in #100 etc.. for all 300 articles I have right now. They are ordered by the category in ascending order. So when I will add a new article (i.e ID #701) that it's title will be "AA" it will go to page #1 – Arye Guetta Nov 15 '15 at 10:00
  • and will be the FIRST in line in the article order. therefor - And all other pages will set accordingly - Article #93 will show NOW page number 2 and Not 1 as it was before. I want to be able to change the order of articles and have the page numbers inside each article to be change accordingly. Thank You – Arye Guetta Nov 15 '15 at 10:01
  • Thanks. I have been trying to follow your suggestion - But I am not sure how to do that exactly? Does Joomla article id and order have attribute that I can refer to? your solution is based on a well knows stricture - I would be happy to know if that can be done with Joomla articles as well? Thanks. – Arye Guetta Nov 15 '15 at 16:13
  • the above mentioned code will sort the articles based on their ids. it is not necessary to have 1 , 2, 3 ids. it will sort even if you have and article id="405" and then id="902" and then id="201" it will sort ascending and id="201" will be first and then 405 and then 902. once you complete the sorting with the above mentioned code. now you can run new jQuery code to set id numbers to 1,2,3,4,5,6 etc and so on. because you will already have sorted articles now you just need to place numbers starting from 1 to until your article exist. let me know you if you need that code also. – Waqas Shakeel Nov 15 '15 at 17:31
  • JQuery is not really what the OP needs here. – Elin Nov 16 '15 at 02:28
  • Thanks Shakeel, As I understand - I will need to maintain the list by myself each and every time I add new article. And my assumption hee is that there is NO way that I can have that hap[pend automatically. Correct? – Arye Guetta Nov 18 '15 at 19:43