1

EDIT:

Using a 3rd party free theme that is called IsleMag.

http://themeisle.com/themes/islemag/

I am wanting to develop it in order to allow users to customise it to see football news that they want to see.

In terms of screenshots, I'm starting the news block from scratch... I'm printing the screenshot below as evidence that I've copied the code you requested into my functions.php file...

[functions.php file]

I am confused though where to put this line of code: "$data = get_the_author_meta( 'user_categories', $user->ID );"

**Please help! :) **


I've tried looking up this solution but haven't got anywhere, even with this guide (can't seem to locate what to put on the index.php file)...

Its for a football news site that I've designed and am running and looking to allow users (football fans) to customise their own homepage to show news articles that are specifically of their chosen post category(ies) (which are teams) - to display news articles (posts) from that category(ies) only.

The web addy is: www.entirelyfootball.co.uk -- please help ASAP!! :)

What I'm basically trying to do is:

1) Add fields in the form of radio (check) boxes in "Your Profile" (individual user profiles) with options like: (1) West Ham United (2) Norwich City 3) Arsenal FC - and allow more than one to be ticked/selected - all of these will be post categories

2) Depending on which fields/options the user has checked (ticked) in their profile, I want to grab this/these category's ID and create a block of news articles on my index.php file that will display the post title, post thumbnail post excerpt (limited to a certain number of characters - say 25) and a link to the individual post... But this must be grabbed by that user's ID and must remember to load the same correct layout the next time the user logs back in.

3) If no fields have been selected, I need an opening if and else(?) statement so that I can fill a default homepage block of news articles that are grabbed from all categories - where none has been set/ticked - so the same layout: post title, post thumbnail, post excerpt (limited to a certain number of characters - say 25) and a link to the individual post.

Can this be done with a PHP if and else statement????

--

It is...

...similar to this (couldn't find the solution in the form of code to put in my index.php file) (removed due to not allowing me to post more than 2 links)

0

First, you will have to add the categories to user profiles. This question has been addressed before. That will give you the possibility to retrieve an array $data with the category ID' a user is interested in.

Now, you will need to turn that array into a list of posts. Depending on where you want to show it, this goes in index.php or sidebar.php or maybe even footer.php. You could also make into a widget. At the location where you eventually need your html you write:

$data = get_the_author_meta( 'user_categories', $user->ID );
if (empty($data)) $data = array (1, 2, 3, 4); // default categories to show

Next you need to define a query which restricts the returned posts to those belonging to a specific category. It wil look something like this:

$query = new WP_Query( array( 'posts_per_page' => 3, 'cat' => $data ) );

Now $query holds an array of max 3 posts in categories with the desired ID's. You can use a foreach loop to go through them in the usual way.

  • Hi @cjbj - How do I include the $query and the $data tags?? Can you write it as an example in what situation you'd write it as? – Morgan McLellan Aug 29 '16 at 13:54
  • @MorganMcLellan That's impossible to tell without more context. Are you developing your own theme or are you using a third party one? In case of the latter, do you have a child theme? Are there hooks in the theme you could use? – cjbj Aug 29 '16 at 14:12
  • do you have an email address or another form of contact as will be able to discuss with screenshots maybe via Facebook or Twitter (way more quicker and able to copy and paste to send screenshots to you)?? Thanks, Morgan – Morgan McLellan Aug 29 '16 at 14:14
  • Please can you email me: morgan@entirelyfootball.co.uk - I'll be able to reply within about 2 minutes so much much quicker – Morgan McLellan Aug 29 '16 at 14:24
  • Please edit your question to clarify it (with images). WPSE is a resource for WordPress developers, not a free helpdesk. So any solution must take place on the site, for others to learn from. – cjbj Aug 29 '16 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.