WordPress.org

Ready to get started?Download WordPress

Forums

How to post specific content in two different areas (13 posts)

  1. moxojo
    Member
    Posted 3 years ago #

    Hi all, thanks in advance for your help. I have just started working with php and wordpress and I think I am a little over my head at the moment. So here is what I would like to do.

    I want to use wordpress for our company website that will have content about our company (services, about, contact, etc) that can be edited by several coworkers using the wp interface as well as typical blog content on a specific page of the site. What I am attempting to do is to have a main content section on each displayed page and a sub content section that is generated by the currently viewed page.

    you can view the website that is being converted over here (currently static):
    smkazoo.com

    and an image of what I am trying to do here:
    http://dev.kalkleen.com/V8/explanation.jpg

    So in summary I would like a content editor to be able to create a post that will appear on a specific page (i have that part working via setting each link in the navigation to go to a category) but then by creating another post having secondary content show up where the sidebar is (possible by using a loop that gets the category name and then add a post that has a sub category named something else). Finally under the blog page having the normal sidebar content (archives, search, etc).

    I hope that makes sense.

    Merry Christmas,

    Thanks!

  2. vtxyzzy
    Member
    Posted 3 years ago #

    I am not clear on how you relate the secondary content to the main post, but you could use a text widget in the sidebar which uses a shortcode to call a function to retrieve the content.

    Do you have a method in mind on how to relate the two parts?

  3. moxojo
    Member
    Posted 3 years ago #

    Hi thanks for your response. My thought was to create web pages that contained the content of categories and sub categories (the website goes three pages deep). So for instance, by creating a sub category (under a "residential" category) called carpet-floors-upholstery I could have a page that displays that post. Then by adding a sub category to that called "sidecontent" (for lack of better term right now) I could run a loop in the sidebar that would get the parent category and then query for another post that had the category of "carpet-floors-upholstery" plus the second category of "sidecontent". I would need the sidebar to be able to recognize what category was being displayed in the main section and then pair it with the second post. Hope that explains better what I am after.

    Thanks!

  4. moxojo
    Member
    Posted 3 years ago #

    Basically I want the users to be able to edit the main content, and secondary content independently for each "page" so that they do not have to worry about the styling, and everything else that is in the sidebar. And each "page" of the site has different main content and different sidebar content. I am open to whatever is the best way and the easiest way to populate those two areas.

  5. vtxyzzy
    Member
    Posted 3 years ago #

    I think this will work, but I think I have seen problems with having the same name for multiple sub-categories. I can't seem to find the article right now, but I think it reported that it is not possible to see what the parent category is when you edit a post that is assigned to a sub-category.

    Other than that, I am reasonably sure the approach is sound. I have used shortcodes in a text widget and I know you can get the child category given the parent.

  6. moxojo
    Member
    Posted 3 years ago #

    thanks for your responses! could you point me in the correct direction for using shortcode in the text widget? or for some help in how to run a query that gets the category of the current page? I think that if I get the category of the page then I could combine that in an array query to only post on that pages sidecontent the content that has that category and also the category of side content, something with the function query_posts(array('category__and' => array(2,6))); might work
    but that is a little out of my league at the moment. I guess my main hiccup right now is knowing how to get the category of the page that I am on, storing it in a variable, then using that variable in the query_posts and requiring the second category before it displays the content.

  7. vtxyzzy
    Member
    Posted 3 years ago #

    To enable shorcodes in widgets, add this to your functions.php (with the appropriate php tags, if needed):

    add_filter('widget_text','do_shortcode');

    If you only have one category assigned to a page, you can use get_the_category().

    Once you have the category id, you can use get_categories() with the 'parent' argument to get the child.

  8. moxojo
    Member
    Posted 3 years ago #

    Okay so here is what I have done, but I am stuck with how to make it actually work.

    In my navigation I have defined links to each category (so when clicked it shows all posts from one category and uses the category.php template).

    Using the query_posts(array('category__and' => array(2,6))); I can get the sidebar to display only the posts that have both the a certain categories name and that are also in the category "sub". My problem is that the ID's have to be hand coded in, I can not get it to work when I try to pass a stored variable to the array. I am sure that it is my lack of php skills at this point. Is it possible to make those id's in the array dynamic somehow? I have stored the category id in a variable using this code `$MyCategory=get_the_category('cat_ID ');
    $CategoryID=$MyCategory[0]->cat_ID ;`

    my problem is that I can't figure out how to pass the `$CategoryID into the above array.

    Thanks for any assistance that you can give.

  9. vtxyzzy
    Member
    Posted 3 years ago #

    I am a little confused by the code you showed. You say you are using this:

    $MyCategory=get_the_category('cat_ID ');
    $CategoryID=$MyCategory[0]->cat_ID ;

    But, get_the_category() needs a POST ID. Is this just a typo?

    The second line gets the category id for the first category found, but you need two category id's for your query. Where is the second category id coming from?

    Anyway, here is how you would use the code above to put $categoryID into the query instead of id 2:

    query_posts(array('category__and' => array($categoryID,6)));

  10. moxojo
    Member
    Posted 3 years ago #

    Sorry for not responding more quickly.

    No it isn't a typo, that is the code that I am using. I am very much a novice yet in php and wordpress so I am not exactly sure how it is working but it is. The call fails when I take that first line out. and $CategoryID is giving me the category ID of the current category that I am viewing. I could be misunderstanding but I thought that the get_the_category() returned the category ID for the current post. Since my links in my main navigation are set to each category when I click on them they should only show the posts assigned to that category thus the function works.

    The second category ID is hard coded in since I know what it is and it will be constant. The idea being that when someone wants a post in a category to go in the side content area they click on the category for which the post should go and also the checkbox for the "sub" category, thus the query pulls the category for the current page and only displays the posts that have that category plus and the sub category assigned to it.

    Thanks again for your help. I have that part working but I can't get the main content to just display the posts that have the category of the page only, now it displays both the posts that have the category of the page as well as the posts that are in the category of the page and have the "sub" category assigned to them.

    It must have something to do with how the category.php pulls the posts. I need it to pull the posts that are only assigned to the one category and that are not assigned to the sub category.

  11. vtxyzzy
    Member
    Posted 3 years ago #

    OK - I suspect that you would get the same results if you take out the 'cat_ID' parameter in the call to get_the_category(). That function must be defaulting to the current post ID if the parameter is not numeric.

    Anyway, in order to be specific about what needs to be done in category.php, I would need to see the code. If there is a call to query_posts using the 'cat=' parameter, it will include children of the category.

    Can you put the category.php code in a pastebin and post a link to it here?

  12. moxojo
    Member
    Posted 3 years ago #

    Okay, thanks, here it is. Note that this code appears to be working as I want it too

    http://wordpress.pastebin.com/86H9hfPm

    The category ID # 8 is for a category called main. What I have done is made a category for the main content and a category for sub content. So when one writes a post they must give it the category and then give it one either sub or main to tell it where it should display. I have put both loop into the above pastebin. It does not seem like an incredibly elegant solution to me. do you foresee any problems with coding it this way?

  13. vtxyzzy
    Member
    Posted 3 years ago #

    If it works, don't fix it!!

    I don't foresee any problems except possibly using two query_posts in a single page. This can sometimes confuse certain plugins. Most of the time you want to create a new query object with $myquery = new WP_Query();.

Topic Closed

This topic has been closed to new replies.

About this Topic