Wordpress multiple / exclusive posting pages - wordpress

I want a site with a separate News and Blog page, ie only news posts are dispayed on news pages and non news posts on blog pages. Also archive lists, category lists, etc for each page must only display relevant posts. Seems like a common requirement, but using the WP documentation, I keep going around in circles!!! Is there a simple way to do this, without getting into multiple blogs, eg using categories.
Thanks

That's easy.
First, you will need to create custom page template. Refer to this page to see how to create it.
Second, on that page (you can copy from your page.php/index.php, the important part is:
if (have_posts()) : while (have_posts()) : the_post();
Find that piece and add this code just right above that code:
query_posts('cat=3&paged='.get_query_var( 'paged' ));
Things to note from above query_posts snippet is:
cat: this is the category ID you want to query. To easily see what ID is on a particular category, you can use ShowID for Post/Page/Category/Tag/Comment plugin.
paged: Paged will allow your custom page to handle next & prev navigations, which is handled by next_post_link() and prev_post_link(). As for get_query_var( 'paged' ) is function to get what page's page you currently see.
Hope that helped.
<shamelessplug>
I blogged it here (in Bahasa Indonesia, which you can easily translate using google translate).
</shamelessplug>

Related

Hide a post but make it accessible via a link Wordpress

I'm trying to hide certain posts from displaying on the site using custom code. I CANNOT USE A PLUGIN!
I would like to do something like IF the page is named the-hidden-page do not display it anywhere on the site BUT someone can access it using a URL... For example, http://thedomain/the-hidden-page.
I haven't been successful finding sample code except for this -
<?php if (is_front_page() && !is_paged()
) $posts = query_posts($query_string . '&cat=-33,-66'); ?>
This code is using category names rather than page names. Also if I used the code above I'm not sure where to add it to. I tried function.php but that didn't work.
Can someone provide an example of how the code could be written to hide post with a certain name?
Also tell me in what file I should add your code to?

if condition for single.php at wordpress

Since I have a blog in blogger(it is a images blog), so I recently moved to wordpress.
After importing all posts from blogger to wordpress it is showing post thumbnail image in single post along with the post original image. So I changed the template. It good working for all imported posts.
But I posted many posts after came to wordpress using a plugin for bulk posting. That template showing thumbnail images in main page , category page etc.. But in single post it is not showing original image.
So I changed template again. Now the images are not showing in imported posts (single post).
So I decided to show separate single.php codes for each category.
So what I need is:
I gathers these 2 codes.
code 1:- (single.php of 1st template)
code 2:-(single.php of 2nd template)
Here I am copying these 2 codes.
In a template single.php code(what ever the template may be) I like to write if condition to solve my problem. I will tell you algorithm but please write the if condition code please. ............
Algorithm:
if( categeory_id=14 or 15 or 16 or 17)
Code 1 here.
else
code 2 here.
Thanks to all developers. If it is not possible please suggest me a good gallery theme.
Thanks in advance.
This should work:
<?php if (is_category( array( 14,15,16,17 ) ))
{
//Code here
}
else
{
//other code
}
?>
In the array put the id of the category. If a category isn't in that array then it will run the other code.

Wordpress - How can I create my own template outside of the expected hierarchy of templates and feed a query to it?

BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
$taxonomyTerm = $_GET['dm_issues'];
$args=array(
'post_type' => 'dm_article',
'dm_issues' => $taxonomyTerm,
'post_status' => 'publish',
);
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below:
if (empty($taxonomyTerm)) {
$taxonomyTerm = 'Default Value';
}
You can create a separate page template. Define the template name at the top of your PHP document:
<?php
/*
Template Name: Printed Page Template
*/
Place your custom query, including all of the content that you need output in this page template... In your WP admin, create a new blank page and assign your new 'Printed Page Template' template to this page. Save it and view the page.

Wordpress - how to show just posts on main index

I have a Wordpress theme that I've been making 'my own' visually and can't seem to get the main content section to display regular posts only - instead of the boxes.
Does anyone know how I can change this without messing it up completely? I've tried stripping everything away and replacing with the 'display all posts loop' thing, but no go. I've tried adding a new page and setting that to show posts and such, but that didn't work either ... all it did was show the latest post.
Any ideas?
Thanks, Jennifer
It depends on what theme you are editing to make your own. If you were editing the default theme one way to do it would be to open index.php, define the template name with something like:
<?php
/*
Template Name: home
*/
?>
and then save it as home.php. In your admin Reading settings set that as your home page.
I am not sure what you mean by "boxes" but I assume you are not interested in the sidebar?
In this file there is one main loop running and it is set to retrieve only the latest post and a sidebar. It pulls in the title of that post : the_title(); the content : the_content(); and the sidebar get_sidebar();. What do you mean by "regular posts"? If you wanted the home page to pull a selection of latest posts you would create your own loop using WP_Query.. something like :
<?php $the_query = new WP_Query('cat=3&showposts=5');
while ($the_query->have_posts()) : $the_query->the_post();?>
Where you are interested in defining the category id (3) and the number of posts to show (5). You can read more on creating these kind of loops here
http://codex.wordpress.org/Template_Tags/query_posts
Good luck :)

Related posts from the blogosphere - dynamic integration of Google Blogsearch RSS on wordpress category pages

I'm looking for a method to put the three latest "news" from Google Blogsearch/Twitter search feeds into the bottom of category Pages. Maybe like this (assuming we're on the archive page for the "Sports" category):
What others say about "Sport":
Instapundit - Michael Jordan Comeback!
Huffington post - Michael Jordan Comeback!
Crazyguy - Michael Jordan Comeback!
So we all know that you can put
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('pathtofeed.com', 3); ?>
in a template-file and it will list the latest three items of a feed.
I would like to put the path to the feed of a query to Google Blogsearch, e.g. [http://blogsearch.google.com/blogsearch_feeds?hl=en&q=sport&ie=utf-8&num=10&output=rss][1]
Works fine. But I would like to replace the sport query with the template tag for the category title - so it dynamically queries Google for a RSS-feed of sport searches. I've tried this:
<?php
include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('www.blogsearch.google.com/blogsearch_feeds?hl=en&q=<?php single_cat_title() ?>&ie=utf-8&num=10&output=rss', 3);
?>
(omitted 'http' cause I can't post hyperlinks here as a new user).
But all I get is:
There was a problem with the feed, try again later.
(translated from Danish error message).
Is it the syntax?
You've got a couple of issues in that code.
The first is you have a <?php inside an already opened <?php section. Concatenation is the answer to that problem.
The second is the function single_cat_title() displays the category title by default. Meaning it "echo()"s it out. So you need to tell that function to return the value not display it.
My solution would be to add a line of code above your include there to get the category you're looking for along the lines of:
$current_category = single_cat_title("", false);
The "false" tells the function to return it as a value instead of displaying it by default, the first parameter is the prefix or the text to display before the category title.
Then concatenate the current_category variable into your include statement
You can check out that function on the Template Tags page in the Wordpress Codex.

Resources