0
votes

I am currently developing a mutlisite wordpress setup, each site is a different language (EG: site.com, site.dk etc).

The sites consist of a number of pages which contain static content, however I also want to include posts (a blog) into both of the sites.

Q1. Is it possible to create a page that shows all the posts listed by latest publish date, with a dropdown that filters by category? How do I do this? Do I need to refer to loop.php?

Basically it should return the following code for all post articles...

<article class="post">
<a href="<URL Link to Post Article>" rel="bookmark">
<figure>
<img title="<Post Title>" alt="<Post Title>" src="<http://url/PostImage.jpg>" width="900" height="600" />
</figure>               
<div class="cover">
<h2>Post Title</h2>
<time pubdate="2013-03-27T21:09:59+00:00">November 18, 2012</time>
</div>
</a>
</article>

Why doesn't this work? It doesn't return anything?

<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article class="post">
<?php get_posts(); ?>
<div id="grid-switcher">
<a href="#" data-block="featured-posts" id="featured">featured</a>
<a href="#" data-block="latest-posts" id="latest" class="active">latest</a>
</div>
<div id="view-blocks">
<div id="latest-post" class="post-grid active">
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(250,250)); // Declare pixel size you need inside the array ?>
<?php endif; ?>
<!-- /post thumbnail -->
<div class="cover">
<h2><?php the_title(); ?></h2>
<time pubdate="<?php the_date(); ?>"><?php the_date('Y-m-d', '<h2>', '</h2>'); ?></time>
</div>
</a>

I have already created a page template portfolio-page.php for the above but cannot findout how to loop through the posts and return them with the above code?

Q2. How do I return a dropdown list with all the categories?

Q3. How do I filter by category from the dropdown list?

Thanks for any help! :)

Sorry I am new to PHP and wordpress...

2

2 Answers

0
votes

The question is a bit vague so I will just share some starting points:

A1) To get a list of posts you can use the get_posts function from wordpress. It already sorts them by the post date desc and you can also add a parameter for the category if one is picked.

A2) To get a dropdown of categories there's a function that does exactly that: wp_dropdown_categories

Check the docs as there are a lot of parameters that can be used with the get_posts function so you should be able to filter them as you wish.

0
votes

I think its a good idea for you to check the database you have wordpress running on.

if you check the wp_posts table you can see the differend fields that you can filter on.

You will be better off using custom query's to filter te posts and order them