• Hi, in my admin panel, I can choose how many posts I would like to display in the RSS feed. Is there a way to access that variable in other areas of my theme? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The only posts setting you have is in the same page and that is global (ie it affects all post listing pages). Anything else requires a custom query in the relevant theme theme template file.
    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

    Thread Starter fishnfrogs

    (@fishnfrogs)

    Hi, thanks for the response. I’m looking for it affect all the pages, so that I only have to edit that number inside the admin panel instead of going through every file and edit the same value. It seems as though there’s a separate global variable for the feeds. Right now, my blog shows 1 post per page and my feed is 10. I’m looking for that ’10’. Is it available. Thanks again!

    It seems as though there’s a separate global variable for the feeds.

    Correct. The settings for both the number of posts in your feed and on your blog pages are in Settings->Reading.

    Thread Starter fishnfrogs

    (@fishnfrogs)

    Is there a way to access that variable in other files I’m using in my theme. So in my other files, when I say:

    query_posts('category_name=CAT&showposts=' . $GLOBAL_FEED_VARIABLE);

    That way I don’t have to edit all the other files I’m using for other reason. I can just make the change in my admin panel instead. Thanks!

    Create a function in functions.php that defines the number of posts per page and then call that function in the template files:

    query_posts('category_name=CAT&showposts=' . my_post_num();

    Then you only have to change one file to cascade the change across all of the relevant pages.

    If you want to grab those settings from Settings->Reading within your code, perhaps something like this:

    $my_posts_per_page = get_option( 'posts_per_page' );
    $my_posts_per_feed = get_option( 'posts_per_rss' );

    http://codex.wordpress.org/Option_Reference

    Then to use it, of course:

    query_posts( 'category_name=CAT&posts_per_page=' . $my_posts_per_page );

    Or, if it’s a feed:
    query_posts( 'category_name=CAT&posts_per_page=' . $my_posts_per_feed );

    showposts is deprecated so I changed it to posts_per_page.

    http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘RSS query variable’ is closed to new replies.