N
N
neoneel2015-09-25 12:44:01
PHP
neoneel, 2015-09-25 12:44:01

How to display all articles of the author?

the bottom line is this: there is a user profile, you need to display all the articles of this user on the profile page, I tried to get by with a crutch:

<?php
if(!class_exists('ContentModelArticle')) require_once JPATH_ROOT.'/components/com_content/models/article.php';
$article = new ContentModelArticle;
$articleId=70;
while($articleId<400){
$youArticle = $article->getItem($articleId);

 if($youArticle->created_by==JUserHelper::getProfile()->id){
echo $youArticle->title;
  echo $youArticle->hits;
echo $youArticle->created;
  echo $youArticle->introtext;
  echo "<p class='readmore'><a href='index.php?option=com_content&view=article&id=".$youArticle->id."'> Подробнее... </a></p>";
 }else{
 echo "У вас пока нет ни одной статьи ";
    echo "  <a href='index.php/submit-an-article'> Написать </a></p>";
 }
 $articleId++; 
}
?>

but gives 404 error, although if instead of $articleId in the line $youArticle = $article->getItem($articleId); put a real value, then it gives out the article that you need

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2015-09-25
@neoneel

More or less like this:

$articles = JModelLegacy::getInstance("Articles", "ContentModel", array("ignore_request" => true));

$articles->setState("params", JFactory::getApplication()->getParams());

$articles->setState("filter.published", 1); // Только опубликованные

$articles->setState("filter.category_id", $this->category->id); // Фильтруем по определенной категории (если надо)
$articles->setState("filter.subcategories", true); // и всем подкатегориям

foreach ($articles->getItems() as $item) { // Получаем все материалы
  if ($item->created_by == $user_id) { // Если это нужный автор, то
    echo $item->title; // выводим все что нужно
  }
}

Correct for Joomla 3.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question