views:

27

answers:

2

Hi All,

I'm developing a Wordpress theme. One of the sections on the front page is titled News. In that section the user should be able to insert information himself (I'll make a separate file called news.php which will php included into the markup), but I also want the content to be automatically updated once the user makes a post.

For example, if the user writes a new post, I want the news section to be automatically updated to something like this:

A new post was written, find it here (where 'here' is a hyperlink pointing to the url of the post).

edit Let me try to give a little more details so it's clearer. The news section will be an unordered list. Thus:

<ul>
<li>
News item 1
</li>
<li>
News item 2
</li>
</ul>

I want the user to be able to add content to the news section, aka make new News Items, but using the visual editor of Wordpress such that the user doesn't have to understand the code and doesn't have to copy/paste the LIs.

Furthermore, whenever a new post is published, I want it to show up as:

"new post published, find it here" where 'here' is a hyperlink with linking to the post.

Is this possible to accomplish?

Thanks, Amit

+1  A: 

If i correctly understood, you need write something like this:

<?php
query_posts(array('posts_per_page' => 1));
the_post();
?>
A new post was written, find it <a href="<?php echo the_permalink();?>">here</a>

Latest news list

<?php
query_posts(array('posts_per_page' => 6));
?>
<ul>
<?php $count=0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
antyrat
This will work?
Amit
Now, how can I make it that the user can add content as well?
Amit
Add comment to what? What user? Post author or another user?
antyrat
Please see my edit...Does that help?
Amit
Only one user will have access to the Wordpress theme (the admin). He will make the posts and manage the news section. But he does not know coding and does not want to copy/paste <li>s
Amit
The code i provided only displays hyperlink to the latest written post, if you need to display last posts in ul>li list just create a new query loop.
antyrat
I've updated my anwer, second section of my answers shows last 6 news at structured ul>li list. Or i don't understood the question correctly?
antyrat
I'm not quite sure how to create new query loops...Could you please point me in the right direction?Also, is it possible to have the front page NOT contain the posts? Almost like it's a static page, except I want the navigation to be updated automatically once a new page is displayed. Is it possible to make this happen? Additionally, will I be able to use wp functions such as the_post(); if it's not in the index.php code (since i'll need to have my posts on a different page)?
Amit
[I'm not quite sure how to create new query loops] - I provide example at the second section of my answer, [ Also, is it possible to have the front page NOT contain the posts?] - Yes, you can use is_home() function to do this, [Additionally, will I be able to use wp functions such as the_post(); if it's not in the index.php code (since i'll need to have my posts on a different page)?] Yes, ofcourse.
antyrat
Man I'm sorry to be bothering you like this and I know this is basic stuff, but I've just never had to deal with this before...I went into Wordpress and set up an articles page to be my posts page, and set up another page to be my static front page. Now if I want to use your code, do I copy/paste it into the HTML editor of my static front page? Will that work, or can you not put php in the HTML editor (my previous experience with it didn't work...).
Amit
ohhh, do I need to use the is_front_page(), and then put this in the index.php file?
Amit
You need to copy/paste it to the source of your php file, not in editor. Editor doesn't recognize php code. [ohhh, do I need to use the is_front_page(), and then put this in the index.php file?] you need to use is_home() insteed.
antyrat
is_home() returns true only for the posts page. I want the news section to show up on the front page (not the posts page). I read on Wordpress.org conditional tags page about the is_front_page(). How come it's not working for me? I have set a "static" page as the front page...
Amit
By the way, the help you're giving me is unbelievable. Thank you so much.
Amit
Nevermind, I solved it. Thank you.
Amit
+2  A: 

make a Categorie, or a Custom Post Type called, "News" so when the user creates a new post, but wants it to be in the "News" section all he has to do is click on the Category "News." You could also create a custom post type, just for "News" and have custom taxonomies etc as well.

Then when you want to print the News post in your theme, write use the query post function and limit the loop to "category_name=news"

philmadelphia
where in the loop do i insert this category_name=news statement?
Amit
before the loop, before you start your if statement. A lot of your questions are basic Wordpress questions man, you need to go to Wordpress.org and do some research, people can't be teaching you the basics.
philmadelphia