daylightstudio / FUEL-CMS-Blog-Module

A blog module for FUEL CMS
18 stars 18 forks source link

blog categories #12

Open gul-ahmad opened 9 years ago

gul-ahmad commented 9 years ago

hi admin i am using the blog module and its very nice ! i want some additon in it as follows i have news and resouces section and both have different pages i want when i go to news page there i want to show news post from news category in admin and when i go to resources page i want to show resouces news from resouces category in admin how i can do this using your blog module

daylightstudio commented 9 years ago

To get the posts from a particular category, you can use the get_category_posts method on Fuel_blog like so:

$posts = $CI->fuel->blog->get_category_posts('resources');
foreach($posts as $post):
     echo $post->title;
endforeach;

Additionally, the blog automatically creates a page for category posts at blog/categories/resources which you could create a route for in your fuel/application/config/routes.php file. http://docs.getfuelcms.com/modules/blog/fuel_blog#func_get_category_posts

gul-ahmad commented 9 years ago

i want to show them on my home page like this i have home view in the views folder and i want to show the post from specifc category on the home page ....You have guided about getting from category within blog module ///

daylightstudio commented 9 years ago

The code above will grab the posts for a particular category and return them as an array of blog_post_model objects.

gul-ahmad commented 9 years ago

<?php $posts = $CI->fuel->blog->get_category_posts('resources'); foreach($posts as $post): echo $post->title; endforeach; ?>

this code gives follwoing error on home view......

A PHP Error was encountered

Severity: Notice

Message: Undefined index: blog_categories

Filename: libraries/Fuel_blog.php

Line Number: 556

and following as well

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'slug= 'resource' GROUP BYfuel_blog_posts.idORDER BYpost_date` desc' at line 7

SELECT fuel_blog_posts.*, fuel_blog_users.display_name, CONCAT(fuel_users.first_name, " ", fuel_users.last_name) as author_name, YEAR(fuel_blog_posts.post_date) as year, DATE_FORMAT(fuel_blog_posts.post_date, "%m") as month, DATE_FORMAT(fuel_blog_posts.post_date, "%d") as day FROM (fuel_blog_posts) LEFT JOIN fuel_relationships ON fuel_relationships.candidate_key = fuel_blog_posts.id AND fuel_relationships.candidate_table = "fuel_blog_posts" AND fuel_relationships.foreign_table = "fuel_blog_categories" LEFT JOIN fuel_blog_users ON fuel_blog_users.fuel_user_id = fuel_blog_posts.author_id LEFT JOIN fuel_users ON fuel_users.id = fuel_blog_posts.author_id LEFT JOIN fuel_blog_categories ON fuel_blog_categories.id = fuel_relationships.foreign_key WHERE .slug= 'resource' GROUP BYfuel_blog_posts.idORDER BYpost_date` desc

Filename: D:\installed softwares\wamp\www\gasification\fuel\codeigniter\database\DB_driver.php

Line Number: 330

daylightstudio commented 9 years ago

What version of FUEL are you running? I'm not able to replicate that error. If you do a print_r on the $tables variable in that method before line 556, what is returned?

gul-ahmad commented 9 years ago

i put this line for it print_r($tables); exit();

it gives only this.....Array ( [search] => fuel_search )

gul-ahmad commented 9 years ago

i am using 1.2 version of fuel

daylightstudio commented 9 years ago

If you comment out "search" in MY_fuel.php for modules_allowed, does it work or if you move the order of search module in that $config['modules_allowed'] array? I vaguely remember an issue with the loading of the configs when the search module and blog module were both loaded together.

gul-ahmad commented 9 years ago

i have commented the search module then it give same output with forms module i also commented that and now it gives... Array ( [blog_posts] => fuel_blog_posts [blog_categories] => fuel_blog_categories [blog_users] => fuel_blog_users [blog_comments] => fuel_blog_comments [blog_links] => fuel_blog_links [blog_settings] => fuel_blog_settings [blog_relationships] => fuel_relationships )

daylightstudio commented 9 years ago

So the forms module seems to be the culprit?

gul-ahmad commented 9 years ago

i have commented the forms module and i need it but commenting it producing the above result so what we will do now...

daylightstudio commented 9 years ago

I think the issue may have to do with line 30 in the Forms_model file (fuel/modules/forms/models/forms_model.php:

parent::__construct('forms'); // table name

Should be:

parent::__construct('forms', FORMS_FOLDER); // table name

I posted a fix for that in the Forms advanced module repo.

gul-ahmad commented 9 years ago

i have tried the above but no changes same result

daylightstudio commented 9 years ago

If you move "blog" to be the last one in the $config['modules_allowed'] it will fix the issue. However, a better fix has been pushed to the develop branch of the blog module. The develop branch has a slew of other changes mostly around adding multi-language support, replying to comments and better spam protection.

gul-ahmad commented 9 years ago

hmmm thats great ..........! but the code is echoing nothing on home view page <?php $posts = $CI->fuel->blog->get_category_posts('resources'); foreach($posts as $post): echo $post->title; endforeach; ?>

daylightstudio commented 9 years ago

On line 572 at the end of the get_category_posts() method, you can add this line to echo out the query that was run. If you run that outside of FUEL, does it return any results. If not, have you associated posts to the "resources" category? $this->CI->blog_posts_model->debug_query();

gul-ahmad commented 9 years ago

i have put this code in the get_category_posts() $posts = $this->CI->blog_posts_model->find_all($where, $order_by, $limit, $offset, $return_method, $assoc_key); //return $posts; echo $this->CI->blog_posts_model->debug_query();

it gives this

SELECT fuel_blog_posts.*, fuel_blog_users.display_name, CONCAT(fuel_users.first_name, " ", fuel_users.last_name) as author_name, YEAR(fuel_blog_posts.post_date) as year, DATE_FORMAT(fuel_blog_posts.post_date, "%m") as month, DATE_FORMAT(fuel_blog_posts.post_date, "%d") as day FROM (fuel_blog_posts) LEFT JOIN fuel_relationships ON fuel_relationships.candidate_key = fuel_blog_posts.id AND fuel_relationships.candidate_table = "fuel_blog_posts" AND fuel_relationships.foreign_table = "fuel_blog_categories" LEFT JOIN fuel_blog_users ON fuel_blog_users.fuel_user_id = fuel_blog_posts.author_id LEFT JOIN fuel_users ON fuel_users.id = fuel_blog_posts.author_id LEFT JOIN fuel_blog_categories ON fuel_blog_categories.id = fuel_relationships.foreign_key WHERE fuel_blog_categories.slug = 'resources' GROUP BY fuel_blog_posts.id ORDER BY post_date desc ......................

and this as well

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: core/Loader.php(332) : eval()'d code

Line Number: 70

daylightstudio commented 9 years ago

If you paste that query into MySQL (e.g. phpMyAdmin or Sequel Pro), what is returned?

gul-ahmad commented 9 years ago

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0016 sec )

gul-ahmad commented 9 years ago

bit i have post related to resources and news-cat category

daylightstudio commented 9 years ago

Are any blog posts directly assigned the category of "resource" (not related posts)?

gul-ahmad commented 9 years ago

i just created a post and assingn the resource category to id but same result

daylightstudio commented 9 years ago

Are you seeing any relationships between blog_posts and the blog_categories tables in the fuel_relationships table?

gul-ahmad commented 9 years ago

yes there is reletion ship in them having id ,candidate_table,candidate_key...blah blah and they have ids .....

daylightstudio commented 9 years ago

And that SQL query doesn't return any results? Are you able to debug that query to see what may be causing no results to show?

gul-ahmad commented 9 years ago

its still returning same result i mean empty result

gul-ahmad commented 9 years ago

i cant understand how the things are goin on in this blog module but failed to do ...please let me know if u could

daylightstudio commented 9 years ago

I'm not able to replicate that issue unfortunately. You can simplify the query for testing down to the following:

SELECT fuel_blog_posts.* FROM (fuel_blog_posts) 
LEFT JOIN fuel_relationships ON fuel_relationships.candidate_key = fuel_blog_posts.id AND fuel_relationships.candidate_table = "fuel_blog_posts" AND fuel_relationships.foreign_table = "fuel_blog_categories" 
LEFT JOIN fuel_blog_categories ON fuel_blog_categories.id = fuel_relationships.foreign_key 
WHERE fuel_blog_categories.slug = 'resources'

This is assuming you have a blog category with a slug value of "resources".