• Alright, here’s what my website currently looks like: https://collegian.csufresno.edu/. It is not powered by Word Press yet, as I’m still trying to figure out how to do it. I want to use Word Press as a CMS.

    As you can see the page is split up into several areas I like to call content blocks. There’s “News,” “Sports,” “Drop Box,” “Opinion,” “Features,” “Video Stories,” “Podcasts,” “Blogs,” “Today’s Front Page,” “Alcohol on Campus,” “Polls,” etc. Each of these content blocks needs to be editable.

    My idea is to make each of the content blocks a category in Word Press. Then make a static index page using many, many loops to call each content block to the page. Here’s the code I’d use:

    <?php $posts = get_posts( “category=X&numberposts=X” ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <?php the_title(); ?> <?php the_content(); ?> <?php endforeach; ?> <?php endif; ?>

    Is this a good idea? Or is there a better way to do this? Any advice would be much appreciated as I’m still new to Word Press. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Or is there a better way to do this?

    That all depends on what you mean by “better way.” If by better you mean easier, probably not. If you mean more efficient, well…

    You do create additional overhead from the various SQL queries on each category’s worth of posts, but just about any method one might arrive at to collect posts in this fashion would effect the same. This is because breaking up your content in this way doesn’t lend itself to one or two queries to the database.

    Beyond all that, what you’re planning will work.

    Thread Starter bryan868

    (@bryan868)

    So basically there isn’t a better way to accomplish what I want?

    Ahem…

    That all depends on what you mean by “better way.”

    Thread Starter bryan868

    (@bryan868)

    Well you said any one method is going to result in lots of calls to the database, so…

    One man’s better way is another man’s headache. ??

    I think Kaf was gently suggesting/hinting that “better way” would be good to define.

    Thread Starter bryan868

    (@bryan868)

    Not sure. Perhaps I just meant to say “another way.” What would be another way to accomplish this? Being new to WP, this method was all I could come up with.

    There is almost always another way to perform some task.

    Is there a smarter way, something that generates less overhead to the database? I’ll answer that with a tentative yes, because though I can imagine it I can’t point you to it. One method might be to cache or save the last X posts for Y categories as they’re published to a physical document you include and parse in your template, which may sound simple but is not a simple bit of coding, to be sure. Or, you might perform a single initial query that collects all posts for these categories, then have a procedure which sorts, orders, restricts and displays everything in their proper place; but that could lead to overhead of a different sort (and again, not a solution a few lines of code solves).

    Honestly, in a world of compromises the *best* way probably is how you’ve planned it out, which is to perform a query for each category of posts. It’s easy to understand, set up, and modify if and when you need to. And for the case of a low to moderately-trafficked site, those extra calls to your database should not cause any undo demand.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Editable content blocks, is there an easier way?’ is closed to new replies.