1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Question to Wordpress and PHP experts

Discussion in 'WordPress' started by Jeffr2014, Mar 17, 2016.

  1. #1
    One of my blogs has an old Weaver 2 theme. I want to keep this theme, as it's almost impossible to find off-the-shelf theme that would allow so many customizations as Weaver 2 does. Yet, I want to improve certain things there, so here is the question:

    Currently, I am using a widget that allows to display popular posts in the sidebar. The code for this in Weaver is:
    [weaver_show_posts cats='popular' show_featured_image='1' hide_top_info="1" hide_bottom_info="1" show='excerpt' excerpt_length='20' orderby="date" sort="DSC" number='6']
    SEMrush
    I am currently using WidgetLogic plugin to display this widget in the sidebar only on a home page. What I want to do is to keep displaying "popular" category posts (as in the code above) on the home page, but to also display a sidebar with relevant posts (i.e. for the same category) on a post page. Ideally, for the post page widget I would like something like this:

    [weaver_show_posts cats=@post_category show_featured_image='1' hide_top_info="1" hide_bottom_info="1" show='excerpt' excerpt_length='20' orderby="date" sort="DSC" number='6']

    where I can specify @post_category variable value per post when I create a new post. Many posts in the blog belong to multiple categories, so I need to be able to specify the "main" category for this post in this variable.

    First question: Is this possible?
    Second question (if the answer to the first one is "yes"): Home many man-hours for an experienced developer will it take to code something like this (i.e. to implement support for @post_category variable)?

    Any thoughts/recommendations are appreciated.
     
    Jeffr2014, Mar 17, 2016 IP
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Note: this answer is based on regular WP-coding, there might be issues with the theme that makes it more complicated (or less, but that is rare)

    Normally, this shouldn't be too hard to do - most likely, one could take the shortcode-function that is already present, and either add to it, or create a second, almost exactly similar code, which would have the category as an extra option. This shouldn't be too hard to do, however, depending on the current coding on the theme, it might involve some modifications to the core files, which _may_ break on update - so it's recommended you create a child-theme to work on, if that's an issue (I dunno if this theme is even updated anymore). I'd say an hour, maybe two at the most. Including some testing and such. Granted, getting this up and running, depending on how many modifications you already have might take a little bit of time as well (I recommend the dev gets a sample data-SQL from you, to work with the same content, and set up WP using the theme and all plugins you have on your site currently - this might take a little bit of time to set up as well, so... yeah - a few hours all included).
     
    PoPSiCLe, Mar 18, 2016 IP
    Jeffr2014 likes this.
  3. Jeffr2014

    Jeffr2014 Active Member

    Messages:
    254
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks a lot PoPSiCLe, I'll try to find somebody to do it then.
     
    Jeffr2014, Mar 18, 2016 IP
  4. Jeffr2014

    Jeffr2014 Active Member

    Messages:
    254
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Just a quick question for you: I assume that the way to specify the main category for the post is to use custom fields approach (i.e. https://codex.wordpress.org/Custom_Fields) and to create a new custom field post_category? This way I can just specify the value for this custom field when create a new post and the modified shorcode function (in shortcodes.php) should be able to access this value using get_post_meta( $post_id, 'listening_to', 'true' );
    Is my understanding correct? If that's the case then it's really 1-2 hours of work at most...

    I am asking this because freelancers that I tried to hire claim that it's a big job and it will take one or two days... I assume they include in this estimate quite a bit of their time to learn how to do this :(
     
    Jeffr2014, Mar 24, 2016 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    PoPSiCLe, Mar 24, 2016 IP
  6. Jeffr2014

    Jeffr2014 Active Member

    Messages:
    254
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    55
    #6
    Because each post may have multiple categories and I want the sidebar to display [relevant] posts only for one of these categories. And I want to be able to specify which category to use for the sidebar (for the particular post) when I publish this post. That's why I need to specify this "main category" field (or category ID) in the "Add New Post" or "Edit Post" WordPress UI... Am I missing something here?
    Basically, this is what I want: if post1 has categories "ABC", "DEF", and "GHI" and I consider the main (i.e. most relevant for this post) category "ABC" then I indicate it (somehow) when publish the post, so when the post is displayed, the sidebar should show the posts for category "ABC" (excl. post1). If post2 has main_category value as "XYZ" then, when the post is displayed, the sidebar should show the posts for category "XYZ" (excl. post2).
     
    Jeffr2014, Mar 24, 2016 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Aha - yes, then custom is the way to go, and that should work just fine - just remember that all posts need to have this selected (posts which haven't gotten this custom value set won't show up at all).
     
    PoPSiCLe, Mar 25, 2016 IP
    Jeffr2014 likes this.